Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Dynamically generate node names Expand / Collapse
Author
Message
Posted Thursday, October 21, 2010 10:18 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Monday, February 4, 2013 6:46 AM
Points: 2, Visits: 24
I need to generate XML results from a query and the node names need to be dynamically generated based on the results of that query. Does anyone know how I can produce xml similar to this?
<root name>
<product_somethingdynamicgoeshere>
<recipes>
<recipe_somethingdynamichere></recipe_somethingdynamichere>
<recipe_somethingdynamichere></recipe_somethingdynamichere>
</recipes>
</root name>

Thanks in advance for your help!
Post #1008640
Posted Thursday, October 21, 2010 11:15 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Tuesday, September 3, 2013 8:24 AM
Points: 1,240, Visits: 5,421
This sounds suspiciously like a homework assignment. The answer to this question is easily found with a little research. The fact that you didn't find it suggests that you didn't even bother to try.

Drew


J. Drew Allen
Business Intelligence Analyst
Philadelphia, PA
Post #1008676
Posted Thursday, October 21, 2010 2:22 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Monday, February 4, 2013 6:46 AM
Points: 2, Visits: 24
Definitely not a homework assignment. I am new to this sort of thing and have managed to
get the data in the following format using a XML Explicit:
<PRODUCT Product_name=something>
....nested tree levels here
</PRODUCT>

and I need to have it appear as <PRODUCT_something> -node name.
If there is an easy solution or if you know somewhere I can check, please pass it along.
Thanks!
Post #1008810
Posted Thursday, October 21, 2010 2:53 PM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Tuesday, September 3, 2013 8:24 AM
Points: 1,240, Visits: 5,421
Depending on the complexity of your query, you could try FOR XML AUTO, ELEMENTS or FOR XML PATH('some value') instead of XML EXPLICIT.

Drew


J. Drew Allen
Business Intelligence Analyst
Philadelphia, PA
Post #1008832
Posted Thursday, October 21, 2010 3:00 PM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Tuesday, September 3, 2013 8:24 AM
Points: 1,240, Visits: 5,421
You may also need to use dynamic SQL. It's really difficult to tell without DDL, sample data, and expected results to work with.

Drew


J. Drew Allen
Business Intelligence Analyst
Philadelphia, PA
Post #1008838
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse