My query is based on the following example
I have table say ‘Table1’. Table1 has one row and one column. The name of the column is ‘Column1’. ‘Column1’ is a text column (NVARCHAR). I have a comma separated keywords like ‘key1,key2..keyn’. I want to search these keywords individually in the column1.
So in the where clause the query should be something like
SELECT ... FROM Table1
WHERE Column1 LIKE '%key1%'
AND Column1 LIKE '%key2%'
AND Column1 LIKE '%keyn%'
I just want to know how to write a query in a simplified manner. Table is quite small and performance is not a main concern.
Just declare the keywords in a variable for the test case
DECLARE @Keywords NVARCHAR(MAX)
SET @Keywords = 'Key1,Key2,Key3'
A simple example will be helpful to me.
This will be easier if you get these into table format. (
SplitTable Valued functions exist to do this to your delimited string – e.g. http://www.eggheadcafe.com/community/aspnet/13/10021854/fnsplit.aspx)