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)
 Error converting parameter in Stored Procedures

Author  Topic 

JMol
Starting Member

3 Posts

Posted - 2004-07-19 : 09:48:42
Is there anyone who has a work around for the following:

I try to give a set of ID's (1,2,3,4,5) to the statement =>
select * from mytable where ID in (@psIDsInString)

This doesn't work because of an error converting the varchar value to a column of data type int
Is there a known work around?

Best regards,

Jeroen

Seventhnight
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2004-07-19 : 09:55:37
Search around here for many solutions...

here is a few:

Create a split function (udf) that returns a recordset then use:

Select * From mytable where id in (select data from dbo.split(@condition))

Use charindex:

Select * From mytable where ("," + @condition + ",") like ("%," + id + ","%)


Dynamic SQL:

Set @sqlStr = 'Select * From mytable where id in(' + @condition + ')'
Execute(@sqlstr)


Corey
Go to Top of Page

ditch
Master Smack Fu Yak Hacker

1466 Posts

Posted - 2004-07-19 : 09:56:52
DECLARE @SQL VARCHAR(4000)

SET @SQL = 'select * from mytable where ID in (' + RTRIM(LTRIM(@psIDsInString)) + ')'

EXEC(@SQL)




Duane.
Go to Top of Page

JMol
Starting Member

3 Posts

Posted - 2004-07-19 : 10:54:03
Thanx!

I used a split function.

Best regards,

Jeroen
Go to Top of Page
   

- Advertisement -