Quantcast
Channel: SQL Errors – SQLSERVERLEARNER
Viewing all articles
Browse latest Browse all 74

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

$
0
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

Viewing all articles
Browse latest Browse all 74

Trending Articles