Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

LIST of Integers for an IN clause... 1

Status
Not open for further replies.

BradF

Programmer
Mar 29, 2005
28
US
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?
 
Check out these two FAQs:

Passing a list of values to a Stored Procedure
faq183-3979

Passing a list of values to a Stored Procedure (Part II)
faq183-5207

--James
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top