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.
He
I am too late here !!! However I found that if employees XML as shown above has multiple records then the JOIN query with CTE returns incorrect results.
I have below XML input
DECLARE @XML1 XML
DECLARE @XML2 XML
SET @XML1 =
'
keith
1005
12/02/1981
ACC001
10,500
keith
1004
12/02/1981
ACC001
10,500
'
SET @XML2 =
'
keith
1005
12/02/1981
ACC001
10,500
keith
1004
12/02/1981
ACC001
10,501
keith1
10040
12/02/1981
ACC001
10,501
'
I will use below query to find the difference
select T.N.value('local-name(.)', 'nvarchar(100)') as NodeName,
T.N.value('.', 'nvarchar(100)') as Value
from @XML2.nodes('/NewDataSet/Employees/Employee/*') as T(N)
EXCEPT
select T.N.value('local-name(.)', 'nvarchar(100)') as NodeName,
T.N.value('.', 'nvarchar(100)') as Value
from @XML1.nodes('/NewDataSet/Employees/Employee/*') as T(N)
Hope this helps !!!