• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 354
  • 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

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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