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

soozhCEOAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

TempDBACommented:
Find out which is a nullable column and change the value with an empty string. To find the nullable column, you can check the schema of the table. Suppose Id field is nullable then put something like this.

http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/Q_28071909.html

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Kent DyerIT Security Analyst SeniorCommented:
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
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Query Syntax

From novice to tech pro — start learning today.