• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 359
  • Last Modified:

Use Comma Delimited String in Stored Procedure

I want to create a stored procedure to delete multiple records in a table.  I'd rather not pass the where statement variables in one at a time, this will get cumbersome.  Instead I would like to pass the values in a string or as an xml document.

I have two options.  First I can loop through the comma delimited values and delete each item individually.  Or I can create my Delete statement with a subquery that will extract the values from the XML document. This would get rid of the loop in the stored procedure but I didn't know what kind of performance I may lose by using a subquery.

My question is which of these two methods should I use?  Can anyone think of a better way to accomplish this task?
0
INFINIEDGE
Asked:
INFINIEDGE
1 Solution
 
SashPCommented:
Insert the record key values into a table.  Call the stored proc to process the values out of the table as the items to delete.

This way you can still encapsulate all of the logic you need in the stored proc but you don't have the limitations of passing a composite field to the stored proc.

Otherwise go with the XML Doc parameter its not that involved.  Try to avoid the comma seperated field if you can.

If you have to go with the comma seperated field populate all of the values into a table in memory before executing the delete statements, you don't want to execute 100s of individual delete statements when you can execute 1.

Cheers Sash
0
 
INFINIEDGEAuthor Commented:
Thanks for the quick response.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now