Atomic Shrimp
Humanoid lifeform
- Local time
- Today, 18:01
- Joined
- Jun 16, 2000
- Messages
- 1,953
I want to construct a custom function that splits a sentence up into words and builds a WHERE clause that I can embed into a SQL statement.
It is to do smart searching on a book titles database, so if the user enters:
CAT DOG TRAIN
the function would convert this to:
WHERE (((BOOKS.TITLE) Like '*CAT*' And (BOOKS.TITLE) Like '*DOG*' And (BOOKS.TITLE) Like '*TRAIN*'))
but if they enter a sentence with only two words:
CAT DOG
the function would return:
WHERE (((BOOKS.TITLE) Like '*CAT*' And (BOOKS.TITLE) Like '*DOG*')
My idea is to do it like this:
-trim the string(to lose spare spaces from the end)
-essentially replace spaces within the string with:
*' And (BOOKS.TITLE) Like '*
then add to the start of the string:
WHERE (((BOOKS.TITLE) Like '*
and add to the end:
*')
I'm sure this will work, but is there an easier way?
Mike
It is to do smart searching on a book titles database, so if the user enters:
CAT DOG TRAIN
the function would convert this to:
WHERE (((BOOKS.TITLE) Like '*CAT*' And (BOOKS.TITLE) Like '*DOG*' And (BOOKS.TITLE) Like '*TRAIN*'))
but if they enter a sentence with only two words:
CAT DOG
the function would return:
WHERE (((BOOKS.TITLE) Like '*CAT*' And (BOOKS.TITLE) Like '*DOG*')
My idea is to do it like this:
-trim the string(to lose spare spaces from the end)
-essentially replace spaces within the string with:
*' And (BOOKS.TITLE) Like '*
then add to the start of the string:
WHERE (((BOOKS.TITLE) Like '*
and add to the end:
*')
I'm sure this will work, but is there an easier way?
Mike