I have a column in a table with sample data as follows:
ServiceTypeIds
7,1
1,9
1
9
4
7
7
In my Where clause I use the following to search on it:
WHERE (@ServiceTypes IS NULL
OR CHARINDEX(','+CAST(SEP.ServiceTypeIDs as VARCHAR(255))+','
, ','+@ServiceTypes+',') > 0)))
If my param @ServieTypes equals ‘1,9’, then I get results, but when it’s @ServiceTypes = ‘1’ or just ‘9’, then I don’t recieve anything back. I’m stuck and tried the above.
I think you have your parameters reversed:
This method works, but only when you are looking for one item (or are lucky and the two items happen to be in the same sequence).