I am facing a problem , I have a query in SQL Server 2014, The query result should be based on a WHERE
clause that takes a string from a C# CheckedListBox
.
I have the string in this form (the following values are for example only) :-
cat,dog,bird,duck
And inside the database the records look like this:-
dog
cat-dog
cat-dog-duck
bird-dog-duck
etc...
I have tried this :-
DECLARE @animals nvarchar(max) = 'dog,bird,cat'
select x,y,z WHERE CHARINDEX(animals, replace(@animals,',',' ')) > 0
The result would show rows with only ONE SINGLE VALUE
like dog
cat
bird
But it wouldn't show rows with values like dog-cat
dog-cat-bird
etc! it just shows rows with one single word from @animals
string.
How can I select all rows where column animals
contains either a word or more from @animals
string.
Thanks in advance...