Forums

This topic is locked

Stored Procedure WHERE with IN

Posted 23 Feb 2004 23:21:43
1
has voted
23 Feb 2004 23:21:43 Matt Mooney posted:
Help!
I've trying make some stored procedures more flexible. I want to use a WHERE clause like:

WHERE (funding IN(@fund))

@fund is getting its value from a session varible that could any of the following:
0,1,2 or 3 or 0,1,2,3 or 4 or 0,1,2,3,4

funding in the DB is an INT, if i hard code the vaules into the WHERE clause, it all works fine. However, I want to pull this from the session variable?


Any ideas???????

Thanks
Matt

Replies

Replied 29 Feb 2004 02:54:00
29 Feb 2004 02:54:00 Phil Shevlin replied:
I'm not expert. But I know most problems with sql are usually related to datatypes. That said, I suspect that @fund is being treated like a single string.

To test my suspicion I just tried this: <pre id=code><font face=courier size=2 id=code> declare @fund int
set @fund = '34,36,52'
select * from mytable
where theID in(@fund)</font id=code></pre id=code>

and got this error: <pre id=code><font face=courier size=2 id=code>Server: Msg 245, Level 16, State 1, Line 2
Syntax error converting the varchar value '34,36,52' to a column of data type int. </font id=code></pre id=code>I'm sure you're on the right track. However, I don't have an answer for you. You may want to try aspmessageboard.com (database forum). There are some very knowledeable people there.

Reply to this topic