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


[HELP] FOR XML


[HELP] FOR XML

Author
Message
knockyo
knockyo
SSC Rookie
SSC Rookie (45 reputation)SSC Rookie (45 reputation)SSC Rookie (45 reputation)SSC Rookie (45 reputation)SSC Rookie (45 reputation)SSC Rookie (45 reputation)SSC Rookie (45 reputation)SSC Rookie (45 reputation)

Group: General Forum Members
Points: 45 Visits: 46
Hi All,

I need use SQL (for xml) to write in this customize format of XML as below:


<track_n_trace tranid="1234" ordernum="ABC123">
<current_location>MY</current_location>
<status code="OK" reason_code="FINE">
<remark>KUU1234</remark>
</status>
<consignment_number>A5555</consignment_number>
<total_shipped overall_qty="0" box_qty="0"/>
</track_n_trace>
Dana Medley
Dana Medley
SSCarpal Tunnel
SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)

Group: General Forum Members
Points: 4308 Visits: 1707
Maybe this will help.


SELECT 1234 AS '@TranID', 'ABC123' AS '@OrderNum',
'MY' AS 'Current_Location',
(
SELECT 'OK' AS '@Code', 'FINE' AS '@Reason_Code', 'KUU1234' AS 'Remark'
FOR XML PATH('Status'), TYPE
) AS 'node()',
'A5555' AS 'Consignment_Number',
(
SELECT '0' AS '@Consignment_Number', '0' AS '@Box_Qty'
FOR XML PATH('Total_Shipped'), TYPE
) AS 'node()'
FOR XML PATH('Track_N_Trace')






Everything is awesome!
knockyo
knockyo
SSC Rookie
SSC Rookie (45 reputation)SSC Rookie (45 reputation)SSC Rookie (45 reputation)SSC Rookie (45 reputation)SSC Rookie (45 reputation)SSC Rookie (45 reputation)SSC Rookie (45 reputation)SSC Rookie (45 reputation)

Group: General Forum Members
Points: 45 Visits: 46
Dana Medley (7/22/2013)
Maybe this will help.


SELECT 1234 AS '@TranID', 'ABC123' AS '@OrderNum',
'MY' AS 'Current_Location',
(
SELECT 'OK' AS '@Code', 'FINE' AS '@Reason_Code', 'KUU1234' AS 'Remark'
FOR XML PATH('Status'), TYPE
) AS 'node()',
'A5555' AS 'Consignment_Number',
(
SELECT '0' AS '@Consignment_Number', '0' AS '@Box_Qty'
FOR XML PATH('Total_Shipped'), TYPE
) AS 'node()'
FOR XML PATH('Track_N_Trace')




Hi,

Thanks your help. It really helping me .. Smile
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