我只是想比较两个xml并尝试将差异存储到另一个名为@DiffXML
的变量中,但会收到名为Incorrect syntax near the keyword 'SET'.
的错误
只是指导修复的内容。感谢
DECLARE @XML1 XML
DECLARE @XML2 XML
DECLARE @DiffXML nvarchar(max)
SET @DiffXML=''
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>'
;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)
)
SET @DiffXML=(select * from
(
select coalesce(XML1.NodeName, XML2.NodeName) as FieldName,
XML1.Value as OldValue,
XML2.Value as NewValue
from XML1
full outer join XML2
on XML1.NodeName = XML2.NodeName
where coalesce(XML1.Value, '') <> coalesce(XML2.Value, '')
) x FOR xml AUTO,elements XSINIL)
print @DiffXML
答案 0 :(得分:1)
从
更改SET @DiffXML=(select * from
到
SELECT @DiffXML=(select * from
您将获得打印结果