SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 [HELP] FOR XML
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

knockyo
Yak Posting Veteran

83 Posts

Posted - 07/22/2013 :  02:34:50  Show Profile  Reply with Quote
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>


Please advice. :)

visakh16
Very Important crosS Applying yaK Herder

India
52249 Posts

Posted - 07/22/2013 :  02:40:19  Show Profile  Reply with Quote
WHere do you get values form? do they come from a table or you pass it through variables?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

knockyo
Yak Posting Veteran

83 Posts

Posted - 07/22/2013 :  02:45:25  Show Profile  Reply with Quote
quote:
Originally posted by visakh16

WHere do you get values form? do they come from a table or you pass it through variables?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs




Hi it came from a table, i able get those values from different table. But i cant generate well the format what I need... :( ... please help
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52249 Posts

Posted - 07/22/2013 :  02:46:46  Show Profile  Reply with Quote
show us the table structure with some sample data and also XML format you want out of it. Otherwise we wont be able to guess out your table columnnames!

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

knockyo
Yak Posting Veteran

83 Posts

Posted - 07/22/2013 :  04:03:21  Show Profile  Reply with Quote
quote:
Originally posted by visakh16

show us the table structure with some sample data and also XML format you want out of it. Otherwise we wont be able to guess out your table columnnames!

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs




Hi,
Below is my code:

select tranid, ordernum,
(SELECT a.status
FROM datafeedactionlog a (nolock)
WHERE a.object_uid = track_n_trace.uid
FOR XML AUTO,TYPE)
from tnt AS track_n_trace
where
track_n_trace.ordernum in ('ABC123')

FOR XML AUTO


But i only able generate the format as this:

<track_n_trace tranid="1234"  ordernum="ABC123>
  <a status="DONE           " />
</track_n_trace>
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52249 Posts

Posted - 07/22/2013 :  04:14:50  Show Profile  Reply with Quote
PLease give us the data in below format as insert scripts. No use in getting the query without any knowledge on table structure and sample data

http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

Sweden
29910 Posts

Posted - 07/22/2013 :  06:39:00  Show Profile  Visit SwePeso's Homepage  Reply with Quote
DECLARE	@Sample TABLE
	(
		TranID SMALLINT NOT NULL,
		OrderNum CHAR(6) NOT NULL,
		Location CHAR(2) NOT NULL,
		StatusCode CHAR(2) NOT NULL,
		ReasonCode CHAR(4) NOT NULL,
		Remark VARCHAR(8) NOT NULL,
		Number CHAR(5) NOT NULL,
		OverallQty TINYINT NOT NULL,
		BoxQty TINYINT NOT NULL
	);

INSERT	@Sample
VALUES	(1234, 'ABC123', 'MY', 'OK', 'FINE', 'KUU1234', 'A5555', 0, 0);

SELECT	TranID AS [@tranid],
	OrderNum AS [@ordernum],
	Location AS current_location,
	StatusCode AS [status/@code],
	ReasonCode AS [status/@reason_code],
	Remark AS [status/remark],
	Number AS [consignment_number],
	OverallQty AS [total_shipped/@overall_qty],
	BoxQty AS [total_shipped/@box_qty]
FROM	@Sample
FOR XML	PATH('track_n_trace');



Microsoft SQL Server MVP, MCT, MCSE, MCSA, MCP, MCITP, MCTS, MCDBA
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.09 seconds. Powered By: Snitz Forums 2000