Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Server 2008: How to compare XML?

Is there are way to compare variables or columns of XML in SQL Server 2008, which is different from comparing a varchar that can be made from the XML value? Some hashing mechanisms?

For example:

declare @xml1 xml = '<Xml1/>'
declare @xml2 xml = '<Xml2/>'
select case when @xml1 = @xml2 then 1 else 0 end 
like image 423
Timofey Avatar asked Jan 13 '11 11:01

Timofey


People also ask

How parse XML in SQL?

First, the sp_xml_preparedocument stored procedure parses the XML document. The parsed document is a tree representation of the nodes (elements, attributes, text, and comments) in the XML document. OPENXML then refers to this parsed XML document and provides a rowset view of all or parts of this XML document.


1 Answers

select case when cast(@xml1 as nvarchar(max)) = cast(@xml2 as nvarchar(max)) then 1 else 0 end 
like image 139
Mikael Eriksson Avatar answered Sep 26 '22 03:09

Mikael Eriksson