Link to home
Start Free TrialLog in
Avatar of soozh
soozhFlag for Sweden

asked on

TSQL Select xml null values

MS SQL Server 2012.

I am using the following select statement to return an XML document:

    set @xmlData = 
        ( select(
          select
            [Id] as 'Id',
            [RegisteringUnitId],
            .....
            [TumorhojdVetEj],
            ....
            [UpdateUserId]
            from OriginalData where Id = @id
          for xml path ('OriginalData2012'), type)
        for xml path('BAUM-registret'), type);

Open in new window


However it does not return columns when the column value is null.

I have see that i can use ELEMENTS XSINIL to include null values but then i get the syntax:

 <TumorhojdVetEj xsi:nil="true"/>

Open in new window


Is there any way just to get an empty tag for null values:

 <TumorhojdVetEj></TumorhojdVetEj>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of TempDBA
TempDBA
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Kent Dyer
NOTE:  There is a difference in TSQL between ISNULL and IS NULL..

Consider Example #C on the following page..

http://technet.microsoft.com/en-us/library/ms184325.aspx

HTH,

Kent