The data types varchar(max) and xml are incompatible in the add operator

Posted on : 16-05-2012 | By : Devi Prasad | In : Msg 402, SQL Errors

0



Error Message:

Msg 402, Level 16, State 1, Line 5
The data types varchar(max) and xml are incompatible in the add operator.

This message occurs when you try to add varchar and xml data types.

Fix:
If you wanted to concatinate the XML Data type and Varchar Data type values, use the CAST Operator on XML Data type to convert into VARCHAR Datatype.

Example:

DECLARE @a XML
DECLARE @b VARCHAR(max)
SET @a = '<A></A>'
SET @b = 'ABC'
SELECT @b + @a

The Above code Gives Error 402.

Fixed Code:

DECLARE @a XML
DECLARE @b VARCHAR(max)
SET @a = '<A></A>'
SET @b = 'ABC'
SELECT CAST(@a AS VARCHAR(max))+@b



Reference : Devi Prasad (sqlserverlearner.com)

Do you like my blog?

If you liked reading this blog, please help spread the word by sharing this blog with your friends.



Need Help On SQL Server?

Cannot Find Solution to your problem (or) If you are looking for some help on SQL Server. Dont worry Click Here to Post your question and solve your issue.




Your Ad Here


Tags: , ,