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 4538702
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T14:50:48+00:00 2026-05-21T14:50:48+00:00

I have a table with an ID (int type) and a blob of XML

  • 0

I have a table with an ID (int type) and a blob of XML data (1 XML type column).
I have 10 rows in the table, and I need to update each XML blob/row seperately.
Is there a way to do this:

Instead of:

    --Works ok to update XML by explicitly entering XML, or one-by-one: 
        declare @XMLNODE table (id int identity, doc xml)
        insert @XMLNODE (doc) values (   
        '
         <Root>
            <Elements>
              <Items>
                <OldItem>

                  <ID>1</ID>
                  <Show Pointer="yes" />
                  <Display Pointer="Display">
                    <Detail1>some Details</Detail1>
                  </DisplayDetails>

                </OldItem>
              </Items>
            </Elements>
            </Root>'
        )

  --This is just an XML variable to get the output, but not related to the ID in table:      
    DECLARE @XMLOutput XML
    SELECT @XMLOutput = ( 
                SELECT  a.value('(ID)[1]','int') as ID,
                a.value('(Show/@Pointer)[1]', 'varchar(5)') AS ShowItem,
                a.value('Display[1]/@Pointer[1]="Display"', 'varchar(10)') as DisplayDetails, -- Set to 'true' or 'false'
                a.value('DisplayDetails[1][@Pointer[1]="Display"]/Detail1[1]', 'varchar(max)') as Detail1
                FROM    @XMLNODE t
                cross apply
                t.doc.nodes('//OldItem') x(a)
                FOR XML PATH ('Items'),
                ROOT('Elements')

        )

Instead, I want to do something like this:

Declare @tempTable table(ID int not null, XMLData xml)
INSERT INTO @tempTable 
SELECT OriginalTable.ID, 
   (--Perform above XML modification per row for each ID and put into a new table) 

–Do this per id to populate @tempTable with ID, XML not just return XML.
Any ideas on getting this to work (is it possible even using a cursor).

  • 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-21T14:50:49+00:00Added an answer on May 21, 2026 at 2:50 pm

    Here is a simplified sample of how you can update the XML column.

    -- Table that holds the XML
    declare @T table(ID int, XMLCol xml)
    
    -- Add sample data
    insert into @T values (1, '<root><val1>1</val1><val2>2</val2></root>')
    insert into @T values (2, '<root><val1>10</val1><val2>20</val2></root>')
    
    -- The cte takes the values out of the 
    -- XML column in the table and modifies them
    ;with cte as
    (
      select 
        T.ID,
        n.r.value('val1[1]', 'int')+1 as val1,
        n.r.value('val2[1]', 'int')+2 as val2
      from @T as T
        cross apply
          T.XMLCol.nodes('/root') as n(r)
    )
    -- Update the XMLCol with the new XML
    update T
      set XMLCol = N.XMLCol
    from @T as T
      inner join cte as C
        on T.ID = C.ID
      cross apply -- Here is the new XML constructed with xml path('')
        (select C.val1, C.val2
         for xml path('root'), type) as N(XMLCol)
    

    Table @T before modify

    ID          XMLCol
    ----------- ---------------------------------------------
    1           <root><val1>1</val1><val2>2</val2></root>
    2           <root><val1>10</val1><val2>20</val2></root>
    

    Table @T after modify

    ID          XMLCol
    ----------- ----------------------------------------------
    1           <root><val1>2</val1><val2>4</val2></root>
    2           <root><val1>11</val1><val2>22</val2></root>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table having 2 columns EmployeeId (int) and EmployeeDetails(XMl type) EmployeeId EmployeeDetails
I have this table: ID(INT) DATE(DATETIME) Under the DATE column there are a lot
I have a table with a column of type INT(7) and I want to
I have a table with a single INT type column that's auto incrementing. is
I have my own type: CREATE TYPE MyType AS TABLE ( foo INT )
I have this Points table: =========================================== FIELD : TYPE =========================================== id int(11) user_id int(11)
i have table with following structure, name (type: TEXT) price (type: INT) color (type:
I have a table with 2 int type columns: one auto increment and primary,
Hey, I have a table with 2 fields of type int which are StatusID
I have a TABLE A( Type INT, Value INT ) Now I want to

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.