Passing a varchar full of comma delimited values to a SQL Server IN function

Of course if you’re lazy like me, you could just do this:

Declare @Ids varchar(50) Set @Ids=",1,2,3,5,4,6,7,98,234,"

Select * from sometable
 where Charindex(','+cast(tableid as varchar(8000))+',', @Ids) > 0

Leave a Comment