I have a variable that is getting filled dynamically by a cursor. It's listed as a VARCHAR(50) and is filled with values (integers) from this cursor followed by a comma so that the final list looks something like this:
@lstVariables = "89,3,23"
Now, taking that variable, I'd like to be able to use it in an IN statement, like:
SELECT * FROM tTable WHERE intID IN (@lstVariables)
Of course it works fine if @lstVariables only contains one value, however if it contains more than one, you get an error:
Syntax error converting the nvarchar value '89,3,23' to a column of data type int.
Is there a way to do what I want without building the query string dynamically?
@lstVariables = "89,3,23"
Now, taking that variable, I'd like to be able to use it in an IN statement, like:
SELECT * FROM tTable WHERE intID IN (@lstVariables)
Of course it works fine if @lstVariables only contains one value, however if it contains more than one, you get an error:
Syntax error converting the nvarchar value '89,3,23' to a column of data type int.
Is there a way to do what I want without building the query string dynamically?