Groups | Blog | Home
all groups > sql server mseq > september 2003 >

sql server mseq : ? on SPROC inputer parameter that accepts a list


Ken
9/22/2003 8:20:01 AM
I'm curious if this is possible using only standard
queries... if not, feel free to post alternate code.

Here is what I'm trying to accomplish...

I have a SPROC like this:

----------------------------------
CREATE PROCEDURE dbo.MyProcedure
@InputString varchar(30) INPUT
AS
SELECT * From Table1
WHERE ID IN (@InputString)
----------------------------------

If I want to provide a list of string values for
@InputString similiar to 'a','b','c', what is the best way
to accomplish this?

Basically, I'd like to be able to call the SPROC (or a
function) something like:

EXEC dbo.MyProcedure 'a','b','c'

Anith Sen
9/22/2003 5:09:08 PM
This is a common question in the .programming newsgroup. You may want to
search the archives there. Also for some ideas refer to:
http://www.algonet.se/~sommar/arrays-in-sql.html

--
- Anith
( Please reply to newsgroups only )

Vishal Parkar
9/23/2003 8:36:36 AM
in addition to anith's post you can try following.

use dynamic sql to do that using EXEC. See following examples

--if parameter you are passing contains varchar values then you can have following syntax.

declare @x nvarchar(500)
select @x='''ALFKI'', ''ANATR'''
exec ('select * from customers where customerid in (' + @x + ')')

--if parameter you are passing contains numeric values then you can have following syntax.

declare @x nvarchar(500)
select @x='5,6'
exec ('select * from orders where employeeid in (' + @x + ')')


--
- Vishal
[quoted text, click to view]

AddThis Social Bookmark Button