December 10, 2003 at 11:24 am
Hell all,
I have a situation where a stored procedure is to delete all records from a table except those with an ID supplied by a user. The challange is that I would like to allow the user to supply a variable number of ID's. The logic is like this:
DELETE tblName
WHERE
tblName.ID <> p1 AND
tblName.ID <> p2 AND
so on ...
Suggestions on how to allow variable number of p's appreciated.
Thank you!
JM
December 10, 2003 at 11:32 am
There have been a couple of threads recently where a set of values is passed in via a single parameter. The query then does a charindex() in order to "parse" those separate values. That should work and you won't have to worry about extraneous parameters you won't necessarily use.
K. Brian Kelley, GSEC
http://www.truthsolutions.com/
Author: Start to Finish Guide to SQL Server Performance Monitoring
K. Brian Kelley
@kbriankelley
December 10, 2003 at 12:28 pm
Insert the exceptions into a temporary table and then delete the rows that don't have IDs in the temporary table.
--Jonathan
--Jonathan
December 10, 2003 at 1:37 pm
Hey, Jonathan, that's a new way!
Not the typical 'how to pass an array' stuff
Frank
--
Frank Kalis
Microsoft SQL Server MVP
Webmaster: http://www.insidesql.org/blogs
My blog: http://www.insidesql.org/blogs/frankkalis/[/url]
December 11, 2003 at 7:03 am
Thank you all,
Just had time to get back to this. I also found the following:
http://vyaskn.tripod.com/passing_arrays_to_stored_procedures.htm
JM
February 17, 2004 at 7:59 am
I would go for the temporary table, sounds like the code is going to be more straightforward with your NOT IN or whatever.
Regards, Hanslindgren
Viewing 6 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply