SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


FOR XML PATH , for NULL column values


FOR XML PATH , for NULL column values

Author
Message
sankyverma38
sankyverma38
SSC Journeyman
SSC Journeyman (80 reputation)SSC Journeyman (80 reputation)SSC Journeyman (80 reputation)SSC Journeyman (80 reputation)SSC Journeyman (80 reputation)SSC Journeyman (80 reputation)SSC Journeyman (80 reputation)SSC Journeyman (80 reputation)

Group: General Forum Members
Points: 80 Visits: 59
Hi All,

I need to create xml from a table. I am using FOR XML in PATH MODE.
But for columns having null value , the node doesn't get created.

I can use ELEMENT XSINIL , but I donot want xsi:nill = true and the namespace to appear in the xml.
As in the below xml :

<Address xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Id>63</Id>
<AccountId>80</AccountId>
<ContactId xsi:nil="true" />
<State xsi:nil="true" />
<ZipCode xsi:nil="true" />
<Region xsi:nil="true" />
<Country>BELGIUM</Country>
</Address>
Please suggest , any other way it is possible to create

<Address>
<Id>63</Id>
<AccountId>80</AccountId>
<ContactId />
<State />
<ZipCode />
<Region />
<Country>BELGIUM</Country>
</Address>

Please suggest
sankyverma38
sankyverma38
SSC Journeyman
SSC Journeyman (80 reputation)SSC Journeyman (80 reputation)SSC Journeyman (80 reputation)SSC Journeyman (80 reputation)SSC Journeyman (80 reputation)SSC Journeyman (80 reputation)SSC Journeyman (80 reputation)SSC Journeyman (80 reputation)

Group: General Forum Members
Points: 80 Visits: 59
This can be done be using ISNULL() check.

SELECT
ISNULL(column_name1,'') AS "ColumnName1",
ISNULL(column_name2,'') AS "ColumnName2"
ISNULL(column_name3,'') AS "ColumnName3"
FROM table FOR XML PATH('Table'), ELEMENTS
jbuys_54
jbuys_54
Old Hand
Old Hand (335 reputation)Old Hand (335 reputation)Old Hand (335 reputation)Old Hand (335 reputation)Old Hand (335 reputation)Old Hand (335 reputation)Old Hand (335 reputation)Old Hand (335 reputation)

Group: General Forum Members
Points: 335 Visits: 84
Brilliant.

Is there a way to do the same with the explicit mode?
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum







































































































































































SQLServerCentral


Search