Compare single value with comma separated columns in SQL SERVER

declare @tmp TABLE (data VARCHAR(10)) 

INSERT INTO @tmp VALUES('1,2,3')

INSERT INTO @tmp VALUES('2,3,5')

INSERT
INTO @tmp VALUES('6,8,9')

Declare @searckeyword varchar(1000)

set @searckeyword = '2'

SELECT data

FROM
@tmp 

WHERE CHARINDEX( ',' + @searckeyword + ',', ',' + data + ',' ) > 0 ;

sql.png

Ebook Download
View all
Learn
View all