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
 Transact-SQL (2000)
 parsing array for stored procedure

Author  Topic 

pl0689
Starting Member

3 Posts

Posted - 2009-01-14 : 19:01:17
I am trying to figure out if it is possible to pass a string array ie.(1,2,3,4) into a stored procedure parameter ie (@list)
so that I dont have to build a SQL string dynamically from my C# code.

exec procedure_call '1,2,3,4'

CREATE PROCEDURE procedure_call
@list varchar(255)
AS
SELECT name,detail
FROM table
WHERE id IN(CAST(@list AS int))
GO

I continuously get "Error converting data type varchar to int".

timmy
Master Smack Fu Yak Hacker

1242 Posts

Posted - 2009-01-14 : 19:23:31
You're trying to convert a text string to integer.

I would create a function that splits a delimited string (there is code on here somewhere - or Google for SQL Delimited split or somthing) then you can do:

SELECT Name, Detail
FROM table
WHERE ID IN (SELECT ID FROM dbo.fnSplitString(@list, ','))

Assuming fnSplitString is the new function and it returns a table with a column called 'ID'

HTH,

Tim
Go to Top of Page

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2009-01-14 : 19:59:31
http://vyaskn.tripod.com/passing_arrays_to_stored_procedures.htm
Go to Top of Page
   

- Advertisement -