Friday, December 4, 2015

MSSQL - Handling NULL Values in XML using XQUERY


declare @xml xml;
select @xml = (
 select
 null as [value]
 for xml path('field'), type, elements xsinil
 );
select @xml;


declare @xml xml
select @xml = N'
 <value xsi:nil="true" />
</field>';

with xmlnamespaces('http://www.w3.org/2001/XMLSchema-instance' as xsi)
select

 @xml.value('/field[1]/value[1][not(@xsi:nil = "true")]', 'datetime')

No comments:

Post a Comment