Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Passing in a list of values of type int

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2004-09-10 : 08:38:08
Richard writes "In a MS SQLServer 7.0 stored procedure I'm trying to get the @IDList variable to be recognized as a list of productids which are of type int. The sample below returns the following error:

Syntax error converting the varchar value '1,2' to a column of data type int.

Any Suggestions?

Declare @Counta int
Declare @IDList varchar(5000)
SET @IDList = '1,2'
print @IDList
SELECT @Counta = COUNT(*)
FROM
vSomething
WHERE
ProductID in ( @IDList ) AND
InfoBPID = 1
AND AppUserID = 76
Print @Counta"

Seventhnight
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2004-09-10 : 08:45:57
[code]
Declare @Counta int
Declare @IDList varchar(5000)

SET @IDList = '1,2'
print @IDList
SELECT @Counta = COUNT(*)
FROM
vSomething
WHERE
(','+@IDList+',') like '%,'+ProductID+',%' AND
InfoBPID = 1
AND AppUserID = 76

Print @Counta
[/code]

Corey
Go to Top of Page
   

- Advertisement -