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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Data Type Convertion 1

Status
Not open for further replies.

jerasi

Programmer
Joined
Jun 19, 2000
Messages
141
Location
CA
I have a stored procedure that gets a parameter @IDsList, @IDsList is a varchar(1000) and it holds a list of IDs i.e. '1,2,3,4,5,6'
I would like to be able to use this list in this query:
Select stuff
From sometable where iID in (@IDsList)
But, I get this error: Syntax error converting the varchar value '1,2,3,4,5,6' to a column of data type int.

How can I do this?

Thank you.
 
Hi,

Try this
Declare @SQL varchar(3000)

SET @SQL = 'Select stuff
From sometable where iID in (' + @IDsList +' )'

exec(@SQL)

Sunil
 
Sunil,

That question is asked so frequently there should be a FAQ created. You seem to have a good handle on the issue. Would you like to create the FAQ? If you want to get the best answer for your question read faq183-874.

Terry L. Broadbent - DBA
SQL Server Page:
 
Hi Terry,

I will create an FAQ on this.

Thanks

Sunil
 
Hi,

I have just created a FAQ on this issue.

Executing Dynamically Created T-SQL Strings
faq183-3132

Please inform me of any additions,suggestion or modifications to the FAQ

Thanks

Sunil

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top