I have some legacy code similar to:
...
'<field1>' +
case when field1 is null then '' else cast( field1 as varchar ) end +
'</field1>' +
...
Which generates the following XML for empty elements:
....
<field1></field1>
...
And I'm replacing the query with FOR XML:
SELECT field1,
...
FOR XML RAW, ELEMENTS
Now, this does not output an element for columns with NULL values. I know about XSINIL:
FOR XML RAW, ELEMENTS XSINIL
But this generates a namespaced empty XML element, which is not compatible with the legacy code reading this output.
...
<field1 xsi:nil="true" />
...
Any suggestions on generating the format below while still using the FOR XML Clause?
....
<field1></field1>
...
Thanks!