{"id":210,"date":"2012-05-16T11:06:57","date_gmt":"2012-05-16T11:06:57","guid":{"rendered":"https:\/\/sqlserverlearner.azurewebsites.net\/2012\/05\/16\/the-data-types-varcharmax-and-xml-are-incompatible-in-the-add-operator\/"},"modified":"2012-05-16T11:06:57","modified_gmt":"2012-05-16T11:06:57","slug":"the-data-types-varcharmax-and-xml-are-incompatible-in-the-add-operator","status":"publish","type":"post","link":"https:\/\/sqlserverlearner.com\/2012\/05\/16\/the-data-types-varcharmax-and-xml-are-incompatible-in-the-add-operator\/","title":{"rendered":"The data types varchar(max) and xml are incompatible in the add operator"},"content":{"rendered":"

Error Message:
\n
\nMsg 402, Level 16, State 1, Line 5
\nThe data types varchar(max) and xml are incompatible in the add operator.
\n<\/font><\/p>\n

This message occurs when you try to add varchar and xml data types.<\/p>\n

Fix:
\nIf 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.<\/p>\n

Example:<\/strong>
\n[sql]
\nDECLARE @a XML
\nDECLARE @b VARCHAR(max)
\nSET @a = ‘<A><\/A>’
\nSET @b = ‘ABC’
\nSELECT @b + @a
\n[\/sql]
\nThe Above code Gives Error 402.<\/p>\n

Fixed Code:
\n[sql]
\nDECLARE @a XML
\nDECLARE @b VARCHAR(max)
\nSET @a = ‘<A><\/A>’
\nSET @b = ‘ABC’
\nSELECT CAST(@a AS VARCHAR(max))+@b
\n[\/sql]<\/p>\n","protected":false},"excerpt":{"rendered":"

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…<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1976,128],"tags":[1977,1978,1979],"class_list":["post-210","post","type-post","status-publish","format-standard","hentry","category-msg-402","category-sql-errors","tag-how-to-add-xml-and-varchar-data-types","tag-how-to-concatinate-xml-and-varchar-data-types","tag-msg-402-level-16-state-1-line-5-the-data-types-varcharmax-and-xml-are-incompatible-in-the-add-operator"],"_links":{"self":[{"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/posts\/210","targetHints":{"allow":["GET"]}}],"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=210"}],"version-history":[{"count":0,"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/posts\/210\/revisions"}],"wp:attachment":[{"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/media?parent=210"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/categories?post=210"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/tags?post=210"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}