sql >> Database >  >> RDS >> Sqlserver

Vergelijk twee sets XML-gegevens met behulp van XQuery in SQL Server

;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, '')    

Resultaat:

NodeName             Value1               Value2
-------------------- -------------------- --------------------
EmpID                1005                 1006
DOB                  12/02/1981           05/02/1981
DeptID               ACC001               ACC002
Salary               10,500               10,900


  1. Verschil tussen codering en sortering?

  2. Waarom slaat de sql-server vraagtekentekens op in plaats van Japanse tekens in NVarchar-velden?

  3. MYSQL - Invoegen als tabel leeg is

  4. Sqoop-export naar MySQL-exporttaak mislukt tool.ExportTool maar kreeg records