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)
 Using a CSV for an 'IN' condition search of a Stored Proc

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2001-07-24 : 08:30:22
kat writes "Is there a way to pass a comma separated list to a stored proc for use in select statement using the 'IN' search condition? I have tried passing a CSV of integer values(which where converted and passed as a varchar) to a stored proc and using the variable, but this was to no avail. Here is a loose example of what I tried:
Here is the proc:

create proc exampleSP(
@passedList varchar(1000)
)
as
begin
select someRecords
from someTable
where someIntField IN (SELECT @passedList)
end


And with the proc here is a query that was executed:

declare @numList varchar(1000)
select @numList = '5401, 5402, 5403, 5404'
execute("exampleSP @passedList=" + @numList)

For the sake of this example, assume that 'someIntField' in 'someTable' contains integer values from 1 to 8000 and just use your imagination for the 'someRecords' field...
I am using SQL Server 7.0, SP3. Thanks in advance for any help!
-KAT"
   

- Advertisement -