I have a varchar(8000) variable that I store a list of integers. They are comma separated. When I feed these into a WHERE IN, such as:
WHERE col1 IN (@mylist)
I get this error:
Conversion failed when converting the varchar value '6,7,8,9' to data type int
This list is built dynamically using something such as:
select @mylist = coalesce(@mylist + ',', '') + cast(numberCol1 as nvarchar)
Any suggestions how I get around the error?