Sqlserver
 sql >> Teknologi Basis Data >  >> RDS >> Sqlserver

Bandingkan dua set data XML menggunakan XQuery di 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, '')    

Hasil:

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


  1. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. Klausa WHERE vs ON saat menggunakan GABUNG

  2. Pernyataan yang disiapkan tidak dapat dieksekusi beberapa kali dengan nilai integer

  3. Waktu Kueri SQL Server Habis

  4. memigrasikan data dari MS SQL ke PostgreSQL?

  5. SQL SERVER 2008 DAPATKAN NILAI YANG TERAKHIR DIMASUKKAN