Friday, February 24, 2012

Avoiding Empty Tags using XML Explicit..

Hey all, a nice little challenge for you as I've searched all over..

Here is some very simple XML Explicit code:

SELECT 1 AS TAG,
NULL AS Parent,
product AS [ParentTag!1!AProduct!Element]

FROM tblTable

WHERE X = Y

FOR XML EXPLICIT

When there is no results, I get an empty tag.

<ParentTag/>

This I do not want. Insted I would like nothing. Is there a simple way to achieve this?

Using SQL Server 2000

Looking forward to your responses!

Roqs

Dunno if its just my SQL Server but mine is working fine. I get a blank when no data is returned (Not the <ParentTag/>)

Tried this with northwind.

SELECT 1 AS TAG,

NULL AS Parent,

CompanyName AS [ParentTag!1!AProduct!Element]


FROM Customers


WHERE CustomerID = 'LFKI'


FOR XML EXPLICIT


No comments:

Post a Comment