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 2000 Forums
 SQL Server Development (2000)
 FOR XML Explicit
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Torch
Starting Member

New Zealand
20 Posts

Posted - 07/21/2005 :  18:08:16  Show Profile  Reply with Quote
I have the following FOR XML EXPLICIT statement:

1 as Tag, null as Parent,
[StageID] as [Stage!1!StageID],
[Stage] as [Stage!1!Stage],
[Update] as [Stage!1!Update]
FROM Stage
FOR XML EXPLICIT

Which gives me results in the form:
<Stage StageID="1" Stage="Stage1" Update="True"/><Stage ......../>

However I want the results in the form:
<Stages><Stage StageID="1" Stage="Stage1" Update="True"/><Stage ......../></Stages>

i.e. with the extra "<Stages></Stages>" at the beginning and end of the xml. Im not sure if this is even possible?

Any help in this matter would be much appreciated.

Torch.

mwjdavidson
Aged Yak Warrior

United Kingdom
735 Posts

Posted - 07/22/2005 :  05:02:09  Show Profile  Reply with Quote
Try this:
SELECT
	1 AS Tag, 
	NULL AS Parent, 
	NULL AS [Stage!1!StageID],
	NULL AS [Stage!1!Stage],
	NULL AS [Stage!1!Update]
UNION 
SELECT
	2 as Tag, 
	1 as Parent,
	[StageID] as [Stage!2!StageID],
	[Stage] as [Stage!2!Stage],
	[Update] as [Stage!2!Update]
FROM Stage
FOR XML EXPLICIT	


Mark
Go to Top of Page

Bunce
Starting Member

Australia
13 Posts

Posted - 08/01/2005 :  07:19:49  Show Profile  Reply with Quote
Hi Mark,

So where have you specified the <stages> tag?
Go to Top of Page

Kristen
Test

United Kingdom
22403 Posts

Posted - 08/01/2005 :  08:46:58  Show Profile  Reply with Quote
Please see my suggestion in http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=53050

Kristen
Go to Top of Page

mwjdavidson
Aged Yak Warrior

United Kingdom
735 Posts

Posted - 08/01/2005 :  11:06:30  Show Profile  Reply with Quote
Sorry, that lost something in translation from my data to Torch's data (and ended up as complete nonsense!) Kristen is absolutely right, it was meant to be:

SELECT 
	1 AS tag, 
	NULL AS parent, 
	NULL AS [Stages!1], 
	NULL AS [Stage!2!StageID],
	NULL AS [Stage!2!Stage],
	NULL AS [Stage!2!Update]

UNION 
SELECT
	2 AS tag, 
	1 AS parent,
	NULL AS [Stages!1], 
	s.[StageID] AS [Stage!2!StageID],
	s.[Stage] AS [Stage!2!Stage],
	s.[Update] AS [Stage!2!Update]
FROM 
	Stages AS s

FOR XML EXPLICIT


Mark
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.06 seconds. Powered By: Snitz Forums 2000