Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Interesting problem
Message
General information
Forum:
Microsoft SQL Server
Category:
Stored procedures, Triggers, UDFs
Environment versions
SQL Server:
SQL Server 2005
Miscellaneous
Thread ID:
01350194
Message ID:
01350550
Views:
21
>>>Hi everybody,
>>>
>>>I'm trying to help someone and I found an interesting problem here http://forums.asp.net/p/1324965/2642788.aspx#2642788
>>>
>>>Suppose we have a Stored Procedure where we pass the list of keywords (comma-delimited list) and we want to have a result where the text may contain any of the passed keywords (in that list).
>>>
>>>Is it possible to write such a statement or we need to use dynamic query with OR for each keyword?
>>>
>>>Thanks in advance.
>>
>>You could use dynamic sql OR you could create a table function where you could SPLIT that parameter and the join the resulting table to that you want.
>
>I don't understand how would you join for OR condition. Looks like OR requires dynamic SQL, I see no other way to construct the query.
DECLARE @lcParameter varchar(max)
SET @lcParameter = 'IN, OUT, CONTAINS, SOMETHING'

SELECT YourTable.*
FROM YourTable
INNER JOIN dbo.Split(@lcParameter) TmpSplit ON YourTable.SomeField LIKE '%'+TmpSplit.TheField+'%'
That could return multiple records if more than one key word is presented in the field but you could use DISTINCT.
I thing Sergey has Split function defined on his site.
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform