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

sqlquery to genrate xml Expand / Collapse
Author
Message
Posted Thursday, August 16, 2012 11:21 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Thursday, December 4, 2014 10:52 PM
Points: 47, Visits: 194


[code="<colname Code="xml"> </colname>"][/code]


Hi

here is the sample of xml code i need to generate .i am new to xml.please help me with sql query to generate as above
Post #1346137
Posted Thursday, August 16, 2012 11:27 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Thursday, December 4, 2014 10:52 PM
Points: 47, Visits: 194
SELECT 'xml' AS 'colname/@classcode'
FOR XML PATH('colname'),TYPE

I need the answer as <colname classcode='xml'/> <colname>


Please help
Post #1346142
Posted Thursday, August 16, 2012 11:48 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Tuesday, December 23, 2014 12:10 PM
Points: 13,330, Visits: 12,829
I would be happy to help...however you first have to provide enough details to answer the question. Look at what you posted and ask yourself if you honestly think somebody can help with only that information.

_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Post #1346161
Posted Thursday, August 16, 2012 2:16 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Thursday, December 4, 2014 10:52 PM
Points: 47, Visits: 194
I am new to this .hope now you will be able to help me out
Post #1346236
Posted Thursday, August 16, 2012 2:25 PM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Tuesday, December 23, 2014 12:10 PM
Points: 13,330, Visits: 12,829
ravidas (8/16/2012)
I am new to this .hope now you will be able to help me out


I will be happy to help you but you still haven't provided any details. You need to provide enough information so that somebody knows what your question is. It is apparent you want to get some xml and that the node name is colname. That is about where the details stop. Do you have a table for the source? What does it look like? Or is this all hardcoded?


SELECT 'xml' AS 'colname/@classcode'
FOR XML PATH('colname'),TYPE

I need the answer as <colname classcode='xml'/> <colname>


Your desired output is not valid xml because your colname node was closed then you have a new colname node.

This will produce valid xml but I have no clue if this is what you want or not.

SELECT 'xml' AS '@classcode'
FOR XML PATH('colname'),TYPE



_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Post #1346238
Posted Friday, August 17, 2012 1:49 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Thursday, December 4, 2014 10:52 PM
Points: 47, Visits: 194
Hi


you have assigned the value for column name but you are not actually closing it

you xml solution will be <colname classcode="xml" />

but in need the solution as <colname classcode="xml" /> <colname>
Post #1346381
Posted Friday, August 17, 2012 7:15 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Tuesday, December 23, 2014 12:10 PM
Points: 13,330, Visits: 12,829
ravidas (8/17/2012)
Hi


you have assigned the value for column name but you are not actually closing it

you xml solution will be <colname classcode="xml" />

but in need the solution as <colname classcode="xml" /> <colname>


The solution you say you need is NOT valid xml. You are closing the tag with />

Then you open a new one with <colname>

You could make it like this (which is valid xml):
<colname classcode="xml"></colname>

But when you have nothing between the opening and closing tags it will compress it exactly what I showed you in my previous post.

declare @xml xml
set @xml = '<colname classcode="xml"></colname>'

select @xml



_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Post #1346528
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse