Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Search by each word in a phrase
Message
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Stored procedures, Triggers, UDFs
Versions des environnements
SQL Server:
SQL Server 2005
Divers
Thread ID:
01331706
Message ID:
01331789
Vues:
11
>Hi everybody,
>
>I'm thinking of writing an SP that would attempt to seach mutltiple fields by each word in a phrase. Here is a part I'm not sure how to handle.
>
>Say, I pass "Name1 Name2" and I need to create a query like this
>
>select ... from ... where (field1 like "Name1%" or field2 like "Name1%" etc.) and (field1 like "Name2" or ...)
>
>I can get a list of words into table valued function, but does it mean I would have to create a dynamic SQL? In this case I don't need an SP, I guess.
>
>Since I would probably have just few words (less than 4, I guess) I may try to code with IF statements...
>
>Appreciate your ideas.
>
>Thanks in advance.

If you use table function why not just JOIN it?
SELECT YoueTable.*
FROM YourTable
INNER JOIN dbo.SomeFunction('List here') Tbl1 ON YourTable.Field1 LIKE Tbl1.Field+'%' OR
                                                 YourTable.Field2 LIKE Tbl1.Field+'%'
But keep in mind that if more than one word is found from Tbl1 you could get duplicated records.
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform