{"id":203,"date":"2012-05-14T07:56:16","date_gmt":"2012-05-14T07:56:16","guid":{"rendered":"https:\/\/sqlserverlearner.azurewebsites.net\/2012\/05\/14\/the-xml-data-type-cannot-be-compared-or-sorted-except-when-using-the-is-null-operator\/"},"modified":"2012-05-14T07:56:16","modified_gmt":"2012-05-14T07:56:16","slug":"the-xml-data-type-cannot-be-compared-or-sorted-except-when-using-the-is-null-operator","status":"publish","type":"post","link":"https:\/\/sqlserverlearner.com\/2012\/05\/14\/the-xml-data-type-cannot-be-compared-or-sorted-except-when-using-the-is-null-operator\/","title":{"rendered":"The XML data type cannot be compared or sorted, except when using the IS NULL operator."},"content":{"rendered":"

Error:<\/strong>
\n
\nMsg 305, Level 16, State 1, Line 1
\nThe XML data type cannot be compared or sorted, except when using the IS NULL operator.
\n<\/font><\/p>\n

Reason for this error message:<\/strong>
\n1) Comparing XML Data type Columns\/Variables.
\n2) Sorting based on XML Data types<\/p>\n

Example Queries:<\/strong>
\n[sql]
\nDECLARE @A XML
\nDECLARE @B XML<\/p>\n

SELECT 1 WHERE @A = @B
\n[\/sql]<\/p>\n

Fix\/Resolution:<\/strong>
\n1) Check if the query contains direct comparisions based on XML Data type columns\/Variables.
\n1) Check if the query uses xml datatype in the order by clause.
\n3) Cast the XML Datatypes to varchar(or some other compatable form) and Compare\/sort.
\n2) Use xquery to Compare\/sort XML Data types values indirectly.<\/p>\n","protected":false},"excerpt":{"rendered":"

Error: Msg 305, Level 16, State 1, Line 1 The XML data type cannot be compared or sorted, except when using the IS NULL operator. Reason for this error message: 1) Comparing XML Data type Columns\/Variables. 2) Sorting based on XML Data types Example Queries: [sql] DECLARE @A XML DECLARE @B XML SELECT 1 WHERE…<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1929],"tags":[1935,1936,1937,1938,1939],"_links":{"self":[{"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/posts\/203"}],"collection":[{"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/comments?post=203"}],"version-history":[{"count":0,"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/posts\/203\/revisions"}],"wp:attachment":[{"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/media?parent=203"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/categories?post=203"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/tags?post=203"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}