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. The table design is pretty poor but I just dont have enough time to create new table and modify the c# code too. I tried to use a Table Value function but since the ServiceTypeIds is not the primary key column, it didnt work. Anyone could help with this?
Just change the positions of arguments for
CHARINDEXi.e. Put','+@ServiceTypes+','as 1st argument and other as second