sample Input Table Details:
Expected Output:
<Geo>
<Continent Name="Asia">
<Country Name="China">
<State Name="Bejing"></State>
</Country>
<Country Name="Japan">
<State Name="Tokyo"></State>
</Country>
</Continent>
<Continent Name="Europe">
<Country Name="Germany">
<State Name="Berlin"></State>
</Country>
<Country Name="France">
<State Name="Paris"></State>
</Country>
</Continent>
</Geo>
How to convert Input relation Data as Above Output XML?
2条答案
按热度按时间sqxo8psd1#
Something like this:
Btw, next time, try to post data as create / insert script, instead of a screenshot, it really saves a lot of typing
r7xajy2e2#
I was just too late copying all the data....
output (after formatting):
More info: FOR XML (SQL Server)
A SELECT query returns results as a rowset. You can optionally retrieve formal results of a SQL query as XML by specifying the FOR XML clause in the query. The FOR XML clause can be used in top-level queries and in subqueries. The top-level FOR XML clause can be used only in the SELECT statement. In subqueries, FOR XML can be used in the INSERT, UPDATE, and DELETE statements. FOR XML can also be used in assignment statements.