Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7541765
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T07:58:47+00:00 2026-05-30T07:58:47+00:00

I have a stored procedure that receives 2 parameters. @username VARCHAR(8), @xmlShiftDays XML I

  • 0

I have a stored procedure that receives 2 parameters.

@username VARCHAR(8), 
@xmlShiftDays XML

I want to delete multiple rows from the database while iterating through the XML.

I have managed to do something similar for an INSERT (see below)

INSERT INTO table(username, date)
   SELECT 
       username = @username, 
       CONVERT(DATETIME,shiftDate.date.value('.','VARCHAR(10)'),103)
   FROM 
       @xmlShiftDays.nodes('/shiftDates/date') as shiftDate(date)

This will successfully insert “x” amount of rows into my table.

I now want to re-engineer the query to DELETE “x” amount of rows. If anyone knows how or could point me in the right direction I would greatly appreciate it.

An example of what I want to achieve is:

DECLARE @username VARCHAR(8)
DECLARE @xmlShiftDays XML 

SET @xmlShiftDays = '<shiftDates><date>21/01/2012</date></shiftDates>'
SET @username = 'A0123456'

DELETE FROM table
WHERE username = @username
AND date = "<b>loop through the nodes in the XML string</b>"
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T07:58:48+00:00Added an answer on May 30, 2026 at 7:58 am

    Assuming you’re using SQL Server 2008 (or newer) for this so I can use the DATE datatype (unfortunately, you didn’t specify in your question which version of SQL Server you’re using)…..

    I would strongly recommend you use a language-independent, regional-settings-independent date format in your XML – use the ISO-8601 format of YYYYMMDD for best results.

    So try something like this:

    DECLARE @xmlShiftDays XML 
    
    SET @xmlShiftDays = '<shiftDates><date>20120122</date><date>20120227</date></shiftDates>'
    
    ;WITH DatesToDelete AS
    (
        SELECT
            DeletionDate = DT.value('(.)[1]', 'date')
        FROM @XmlShiftDays.nodes('/shiftDates/date') AS SD(DT)
    )
    SELECT * FROM DatesToDelete
    

    This should give you the two dates combined into XML string – right?

    Now, you can use this to do the deletion from your table:

    DECLARE @username VARCHAR(8)
    DECLARE @xmlShiftDays XML 
    
    SET @xmlShiftDays = '<shiftDates><date>20120122</date><date>20120227</date></shiftDates>'
    SET @username = 'A0123456'
    
    ;WITH DatesToDelete AS
    (
        SELECT
            DeletionDate = DT.value('(.)[1]', 'date')
        FROM @XmlShiftDays.nodes('/shiftDates/date') AS SD(DT)
    )
    DELETE FROM dbo.Table
    WHERE username = @username
    AND date IN (SELECT DeletionDate FROM DatesToDelete)
    

    Does that work for you?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a stored procedure that returns around 1000 rows. I want to SELECT
I have a stored procedure that returns multiple tables. How can I execute and
I have a Stored Procedure that rolls-back a series of operations. I want to
I have a stored procedure that returns values from a temp table. In my
I have a stored procedure that executes much faster from Sql Server Management Studio
I have a stored procedure that has a bunch of input and output parameters
I have a stored procedure that receives a date value like this: @AsOf date
I have a stored procedure, PROC , which receives some parameters. If one of
I have a stored procedure that receives a string parameter OrderByColumn and builds dynamic
I have a strange, sporadic issue. I have stored procedure that returns back 5

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.