Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Use Comma Delimited String in Stored Procedure

Posted on 2004-10-26
2
Medium Priority
?
349 Views
Last Modified: 2006-11-17
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
Comment
Question by:INFINIEDGE
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 8

Accepted Solution

by:
SashP earned 200 total points
ID: 12411321
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
 

Author Comment

by:INFINIEDGE
ID: 12411574
Thanks for the quick response.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have a large data set and a SSIS package. How can I load this file in multi threading?
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question