XML – SQLSERVERLEARNER https://sqlserverlearner.com LEARN SQL SERVER ONLINE Mon, 14 May 2012 07:56:16 +0000 en-US hourly 1 https://wordpress.org/?v=6.5.3 The XML data type cannot be compared or sorted, except when using the IS NULL operator. https://sqlserverlearner.com/2012/05/14/the-xml-data-type-cannot-be-compared-or-sorted-except-when-using-the-is-null-operator/ https://sqlserverlearner.com/2012/05/14/the-xml-data-type-cannot-be-compared-or-sorted-except-when-using-the-is-null-operator/#respond Mon, 14 May 2012 07:56:16 +0000 https://sqlserverlearner.azurewebsites.net/2012/05/14/the-xml-data-type-cannot-be-compared-or-sorted-except-when-using-the-is-null-operator/ 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 @A = @B
[/sql]

Fix/Resolution:
1) Check if the query contains direct comparisions based on XML Data type columns/Variables.
1) Check if the query uses xml datatype in the order by clause.
3) Cast the XML Datatypes to varchar(or some other compatable form) and Compare/sort.
2) Use xquery to Compare/sort XML Data types values indirectly.

]]>
https://sqlserverlearner.com/2012/05/14/the-xml-data-type-cannot-be-compared-or-sorted-except-when-using-the-is-null-operator/feed/ 0
Msg 206, Level 16, State 2, Line 6 Operand type clash: int is incompatible with xml https://sqlserverlearner.com/2012/05/11/msg-206-level-16-state-2-line-6-operand-type-clash-int-is-incompatible-with-xml/ https://sqlserverlearner.com/2012/05/11/msg-206-level-16-state-2-line-6-operand-type-clash-int-is-incompatible-with-xml/#respond Fri, 11 May 2012 12:39:35 +0000 https://sqlserverlearner.azurewebsites.net/2012/05/11/msg-206-level-16-state-2-line-6-operand-type-clash-int-is-incompatible-with-xml/ Error:

Msg 206, Level 16, State 2, Line 6
Operand type clash: int is incompatible with xml

This error comes up when you try to set XML variable with an int value.

Sample Code:
[sql]
DECLARE @Var1 XML
DECLARE @Var2 INT

SET @Var2 = 1

SELECT @Var1 = @Var2
[/sql]

When you execute the above code you get this error at line 6
SELECT @Var1 = @Var2

Fix:
Check all the XML related variables, columns in the table, Arguments to stored procedure, function etc…
and validate if the correct XML value is set.

Applicable to SQL Server 2000,SQL Server 2005,SQL Server 2008,SQL Server 2008 r2,SQL Server 2012, SSIS

]]>
https://sqlserverlearner.com/2012/05/11/msg-206-level-16-state-2-line-6-operand-type-clash-int-is-incompatible-with-xml/feed/ 0