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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:19:37+00:00 2026-05-28T01:19:37+00:00

Suppose I store employee data in a xml column in my log table. Sometimes

  • 0

Suppose I store employee data in a xml column in my log table. Sometimes data is also updated in the xml column from a stored procedure.

Here is the sample example

DECLARE @XML1 XML
DECLARE @XML2 XML

SET @XML1 = 
'<NewDataSet> 
<Employee>
<EmpID>1005</EmpID>
<Name> keith </Name>
<DOB>12/02/1981</DOB>
<DeptID>ACC001</DeptID>
<Salary>10,500</Salary>
</Employee>
</NewDataSet>'

SET @XML2 = 
'<NewDataSet> 
<Employee>
<EmpID>1006</EmpID>
<Name> keith </Name>
<DOB>05/02/1981</DOB>
<DeptID>ACC002</DeptID>
<Salary>10,900</Salary>
</Employee>
</NewDataSet>'

There is some difference in two the xml data which I need to show like old value & new value as a output of sql

Old Value             New Value
---------             ---------
1005                  1006
12/02/1981            05/02/1981
ACC001                ACC002
10,500                10,900

I just need to show the difference like above. So please guide me how to compare two xml data using XQuery and show the difference only in the above fashion in SQL Server. Please guide me with code snippet. thanks

  • 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-28T01:19:38+00:00Added an answer on May 28, 2026 at 1:19 am
    ;with XML1 as
    (
      select T.N.value('local-name(.)', 'nvarchar(100)') as NodeName,
             T.N.value('.', 'nvarchar(100)') as Value
      from @XML1.nodes('/NewDataSet/Employee/*') as T(N)
    ),
    XML2 as
    (
      select T.N.value('local-name(.)', 'nvarchar(100)') as NodeName,
             T.N.value('.', 'nvarchar(100)') as Value
      from @XML2.nodes('/NewDataSet/Employee/*') as T(N)
    )
    select coalesce(XML1.NodeName, XML2.NodeName) as NodeName, 
           XML1.Value as Value1, 
           XML2.Value as Value2
    from XML1
      full outer join XML2
        on XML1.NodeName = XML2.NodeName
    where coalesce(XML1.Value, '') <> coalesce(XML2.Value, '')    
    

    Result:

    NodeName             Value1               Value2
    -------------------- -------------------- --------------------
    EmpID                1005                 1006
    DOB                  12/02/1981           05/02/1981
    DeptID               ACC001               ACC002
    Salary               10,500               10,900
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have a table with a column name varchar(20) , and I store
I want to select some data from db and store in an array. Suppose
Suppose you store instances of a class in a relational table. How would you
On the Mac OS, from what I understand you're suppose to store information in
Suppose I have a stored procedure that manages its own transaction CREATE PROCEDURE theProc
Suppose I have any data stored in bytes. For example: 0110001100010101100101110101101 How can I
Suppose I have a PL/SQL stored procedure as follows: PROCEDURE do_something(foo VARCHAR2 DEFAULT NULL)
I am doing this query in a stored procedure: SELECT TOP 1 [Employe] FROM
How can I store m:m relationship data in a database? Suppose m knows knows
Suppose I want to fetch data into an anonymous object (i.e. fetch data from

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.