Wrox Home  
Search P2P Archive for: Go

  Return to Index  

sql_language thread: sp parameters with unknown number or value


Message #1 by Joshua Prentice <JPrentice@e...> on Tue, 6 Nov 2001 09:19:07 -0500
This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.

------_=_NextPart_001_01C16711.A6A2C678
Content-Type: text/plain;
	charset="iso-8859-1"

There might be a better way of doing this, but this is the best that I can
think of off the top of my head:

CREATE PROCEDURE proc_name
@Code VarChar(100)	-- to allow for enough values
AS

SET NOCOUNT ON

DECLARE @SQL VarChar(300)

SET @SQL = 'SELECT 
           FROM dbo.SUBEVNT.MyTable
           WHERE dbo.SUBEVNT.eventid IN (' + @Code + ')

EXEC (@SQL)

Pass through @Code in the form: '''XYZ'',''ABC'',''MNO'''
ie you end up with a string that interprets as "'XYZ','ABC','MNO'" (to
illustrate using " to delimit the string)

You were also missing a FROM clause in you post.

regards
David Cameron
nOw.b2b
dcameron@i...

-----Original Message-----
From: Joshua Prentice [mailto:JPrentice@e...]
Sent: Wednesday, 7 November 2001 12:19 AM
To: sql language
Subject: [sql_language] sp parameters with unknown number or value


I would like to create a stored procedure where the IN statement is a
variable that can have multiple values.
The code looks something like the following:

CREATE Procedure proc_name
	@Code varchar(3)
AS select dbo.SUBEVNT.eventid
where dbo.SUBEVNT.eventid IN (@Code

@CODE can be:
	('ABC','DEF')
	Or
	('ABC','XYZ')
	Or
	('XYZ','ABC','MNO')
	Or 
	('ABC')
Or a dozen other @code values and combinations of @code values which the
user will key into an field on an asp page.

How can this be done in any effective manner?  Any ideas?




  Return to Index