[dba-SQLServer] FOR XML EXPLICIT

Francisco Tapia fhtapia at gmail.com
Fri Aug 12 12:02:35 CDT 2005


Happy Friday to all, 
This is not really that long, but I've included code to help simplfy what 
I'm talking about...

I have the following FOR XML Select, it produces the a valid XML object.

SELECT Top 1 
1 as TAG,
0 AS Parent,
PONUM [Header!1!PONUM!element],
RRDate [Header!1!RRDate!element],
NULL [OrderItems!2!CPN!element],
NULL [OrderItems!2!AddedDate!element]
FROM tbl_RR WHERE PONUM = '50803-01HB'

UNION ALL

SELECT 2 AS TAG,
1 AS Parent,
R.PONUM [OrderItems!2!PONUM!element],
NULL,
CPN [OrderItems!2!CPN!element],
AddedDate [OrderItems!2!AddedDate!element]
FROM tbl_RR R 
INNER JOIN tbl_RRLineItems RL
ON R.RRID = RL.RRID 
WHERE R.PONUM = '50803-01HB'
FOR XML EXPLICIT

The XML object looks like this:
<Header>
<PONUM>5080301HB</PONUM>
<RRDate>20050810T07:51:40.633</RRDate>
<OrderItems>
<CPN>925</CPN>
<AddedDate>20050810T07:51:40.680</AddedDate>
</OrderItems>
</Header>

This is almost where I need this, the xml that I'm trying to match is 
formated in this manner:
<WSOrder>
<Header>
<PONUM>5080301HB</PONUM>
<RRDate>20050810T07:51:40.633</RRDate>
</Header>
<OrderItems>
<WSOrderItem>
<CPN>925</CPN>
<AddedDate>20050810T07:51:40.680</AddedDate>
</WSOrderItem>
</OrderItems>
</WSOrder>

Since I'm almost there, I'm sure I just need to modify my Select (For XML) 
with maybe 2 more union alls, but I was wondering if anyone has done it this 
way before and could lend a pointer in the right direction :)

Thanks,
-- 
-Francisco
http://pcthis.blogspot.com |PC news with out the jargon!
http://sqlthis.blogspot.com | Tsql and More...



More information about the dba-SQLServer mailing list