Where value in column containing comma delimited values

There is one tricky scenario. If I am looking for ’40’ in the list ‘17,34,400,12’ then it would find “,40” and return that incorrect entry. This takes care of all solutions:

WHERE (',' + RTRIM(MyColumn) + ',') LIKE '%,' + @search + ',%'

Leave a Comment