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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T06:40:50+00:00 2026-05-15T06:40:50+00:00

How can I update the value of an xml tag with the value of

  • 0

How can I update the value of an xml tag with the value of an xml tag from another related table?

something like this:

UPDATE v2
 SET
 [xml].modify ('replace value of (//TAG1/text())[1] 
                with "CAST(v1.[xml].query(''//TAG2'') AS NVARCHAR(MAX))"')
FROM 
 table2 v2, 
 table1 v1 
WHERE
 v2.id = v1.id
  • 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-15T06:40:51+00:00Added an answer on May 15, 2026 at 6:40 am

    I don’t think you can do this in a single step – but you can do it in two steps, if you’re on SQL Server 2008:

    DECLARE @NewValue NVARCHAR(50)
    
    SELECT @NewValue = [xml].value('(//TAG2)[1]', 'NVARCHAR(50)')
    FROM dbo.v1 
    WHERE id = 1
    
    UPDATE dbo.v2
    SET [xml].modify('replace value of (//TAG1/text())[1] with sql:variable("@NewValue")')
    WHERE id = 1
    

    The ability to specify a sql:variable in your replace value of XQuery is a new feature in SQL Server 2008 – so if you’re stuck on 2005, this won’t work, unfortunately.

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

Sidebar

Related Questions

i would like modify text of xml tag value i have used an xml
Can I check if the update value is N , then skip this field?
How can one update an attribute value in DynamoDB table to ? one option
How can I update multiple values in MySQL? This didn't work: UPDATE test SET
How can I get data from an xml web service (say, the value of
I have a xml document that has a record set like this. <document> <row>
I have XML something like this: <?xml version=1.0?> <a xmlns=http://mynamespace> <b> <c val=test />
I have an xml that looks something like this <para> text text text <b>text</b>
I've got something like the following XML file. <credits> <property name=tag> <item>v0003</item> </property> <property
How can I update the value of tags in an XML file using System.Xml?

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.