SQL and XML shaping - true\false data values used to create the XML elements

dracula51

New Member
The solutions to this is eluding me and I am hoping you can help.The data set from table [restrictions] looks like this\[code\] item_uid include the_value 00035061 FALSE 'AZ' 00035061 FALSE 'CA' 00035061 TRUE 'NC' 00035061 TRUE 'SC'\[/code\]The intended XML result should look like:\[code\]<item> <item_uid>00035061</item_uid> <restrictions> <inclusions> <include>NC</include> <include>SC</include> </inclusions> <exclusions> <exclude>AZ</exclude> <exclude>CA</exclude> </exclusions> </restrictions><item>\[/code\]I can assemble each side seperately;\[code\]SELECT the_value AS 'data()'FROM restrictionsWHERE include = TRUE AND item_uid = '00031762'FOR XML PATH ('include'), ROOT ('inclusions')\[/code\]And then \[code\]SELECT the_value AS 'data()'FROM restrictionsWHERE include = FALSE AND item_uid = '00031762'FOR XML PATH ('exclude'), ROOT ('exclusions')\[/code\]but can not figure out how to generate this XML in one SQL statement. Thanks for your assistance!
 
Back
Top