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)
 Pass array of parameters to stored procedure

Author  Topic 

pl0689
Starting Member

3 Posts

Posted - 2009-01-15 : 11:12:51

I am trying to figure out a way to pass a string array ie.(1,2,3,4,5) into a stored procedure parameter ie (@list)
It would work as follows:

procedure_call '1,2,3,4'

CREATE PROCEDURE procedure_call
@list varchar(255)
AS
SELECT * FROM mytable
WHERE id IN(CAST(@list AS int))
GO

I continuously get "Error converting data type varchar to int". Has anyone ever been successful in doing this through a stored procedure.

dinakar
Master Smack Fu Yak Hacker

2507 Posts

Posted - 2009-01-15 : 11:16:50
yes...a lot... either search on these forums or I have an article on my blog about similar question.

Dinakar Nethi
************************
Life is short. Enjoy it.
************************
http://weblogs.sqlteam.com/dinakar/
Go to Top of Page

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2009-01-15 : 11:22:51
http://vyaskn.tripod.com/passing_arrays_to_stored_procedures.htm
Go to Top of Page

pl0689
Starting Member

3 Posts

Posted - 2009-01-15 : 13:07:41
Thanks alot dinkar and sodeep. Both are fantastic solution. In my scenario i am going with scenario 6 from this article
http://vyaskn.tripod.com/passing_arrays_to_stored_procedures.htm
Go to Top of Page

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2009-01-15 : 13:18:28
quote:
Originally posted by pl0689

Thanks alot dinkar and sodeep. Both are fantastic solution. In my scenario i am going with scenario 6 from this article
http://vyaskn.tripod.com/passing_arrays_to_stored_procedures.htm




Welcome
Go to Top of Page

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-01-15 : 23:14:06
declare @list varchar(32)
select @list = '1,5,7'
SELECT * FROM urtable
WHERE ','+@list+',' LIKE '%,'+CAST(id AS VARCHAR(256))+',%'
Go to Top of Page
   

- Advertisement -