Solved

Use Comma Delimited String in Stored Procedure

Posted on 2004-10-26
325 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
Question by:INFINIEDGE
    2 Comments
     
    LVL 8

    Accepted Solution

    by:
    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
    Thanks for the quick response.
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
    Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
    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 the fundamental information of how to create a table.

    913 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

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now