Click here to Skip to main content
15,894,405 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

i have face one error like SQL Query Select Case statement with evaluate XML data type columns, but i was trying to more than time to get the error like.

ERROR:The XML data type cannot be compared or sorted, except when using the IS NULL operator.

this is my SQL query:-
Select TOP 1000 [AccountsPayable_Content].ItemID,[AccountsPayable_Content].C2SID_SUBJECT, [AccountsPayable_Content].C2SID_CREATOR,
[AccountsPayable_Content].C2SID_DATE, [AccountsPayable_Content].KEYWORDS,CASE [AccountsPayable_Content].C2SID_Notes WHEN ISNULL([AccountsPayable_Content].C2SID_Notes)THEN "0" else "1" end,
[AccountsPayable_Content].LastName" FROM AccountsPayable_Content
Posted

1 solution

You cannot group by XML or TEXT columns, you have to first convert it to varchar(max).

Try:
SQL
SELECT 
    TOP 1000 [AccountsPayable_Content].ItemID,
    [AccountsPayable_Content].C2SID_SUBJECT, 
    [AccountsPayable_Content].C2SID_CREATOR,
    [AccountsPayable_Content].C2SID_DATE, 
    [AccountsPayable_Content].KEYWORDS,
    CASE [AccountsPayable_Content].C2SID_Notes 
       WHEN ISNULL(CONVERT(xml,CONVERT(varchar(max),[AccountsPayable_Content].C2SID_Notes)) NotesXML)
       THEN 
            "0" 
       ELSE
            "1" 
    END,
    [AccountsPayable_Content].LastName" 
FROM 
    AccountsPayable_Content


Details here: Limitations of the xml Data Type[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900