I only want to show the categoryid node and value if its not an empty guid. I've tried different formats but nothing worked. It keeps just printing the if statement as a string in the results. I read that you had to have an else condition as part of your code, can I just put an empty string there? I've looked through a few articles online about this and the msdn reference with no luck. For some reason it's evaluating my if statement.
declare @XML xml = N'
<books>
<book>
<title>Book 1</title>
<categoryid>00000000-0000-0000-0000-000000000000</categoryid>
<author>Chris</author>
<price>10</price>
</book>
<book>
<title>Book 2</title>
<categoryid>DF3D696D-B7A3-44A2-BC7D-1D45745C979B</categoryid>
<author>Spencer</author>
<price>20</price>
</book>
</books>';
select @XML.query(
'<books>
{
for $b in /books/book
return
<book>
{$b/title}
{$b/price}
if(not($b/categoryid = 00000000-0000-0000-0000-000000000000))
then {$b/categoryid}
else
</book>
}
</books>'
);