select first name
,last name
,employeeID
,CASE
WHEN CONVERT(xml,detail).value('count(//education/item)','nvarchar(50)')=0 AND
CONVERT(xml,detail).value('(//preventive/itemValue/text())[1]','nvarchar(50)') LIKE '%Employee refuses to participate %' THEN
'AAA-1'
WHEN CONVERT(xml,detail).value('count(//education/item)','nvarchar(50)') =0 AND
CONVERT(xml,detail).value('count(//preventive/itemValue)','nvarchar(50)')=0 THEN
'AAA-2'
ELSE
'AAA-3'
END val
,Start Date
,End Date
FROM (HAS MULTIPLE JOINS HERE & CONDITION )
GROUP BY first name
,last name
,employeeID
,CASE
WHEN CONVERT(xml,detail).value('count(//education/item)','nvarchar(50)')=0 AND
CONVERT(xml,detail).value('(//preventive/itemValue/text())[1]','nvarchar(50)') LIKE '%Employee refuses to participate %' THEN
'AAA-1'
WHEN CONVERT(xml,detail).value('count(//education/item)','nvarchar(50)') =0 AND
CONVERT(xml,detail).value('count(//preventive/itemValue)','nvarchar(50)')=0 THEN
'AAA-2'
ELSE
'AAA-3'
END
,Start Date
,End Date
My code is executing perfectly fine, but when I write the group by clause it throws an error saying that XML data type cannot be grouped. I know we can do it by user defined function. Can anyone please let me know how this task can be achieved. I need to have to group by clause in my code. I'm using SQL Server 2005/2008.