sql server 2008 - XML data within tags -


i'm using microsoft sql server 2008 r2 , new xml. have query generates output looks this:

<user id="12345">  --same user id   <user_type>student</user_type>   <name_first>jane</name_first>   <name_last>smith</name_last>   <email>jsmith@somedomain.com</email>   <transcript>     <course id="acc101">       <title>accounting 101</title>       <credits>3.0000</credits>       <grade>b</grade>     </course>   </transcript> </user> <user id="12345">  --same user id   <user_type>student</user_type>   <name_first>jane</name_first>   <name_last>smith</name_last>   <email>jsmith@somedomain.com</email>   <transcript>     <course id="eng151">       <title>english 151</title>       <credits>3.0000</credits>       <grade>a</grade>     </course>   </transcript> </user> <user id="12345">  --same user id   <user_type>student</user_type>   <name_first>jane</name_first>   <name_last>smith</name_last>   <email>jsmith@somedomain.com</email>   <transcript>     <course id="mat102">       <title>math 102</title>       <credits>3.0000</credits>       <grade>b</grade>     </course>   </transcript> </user> 

but want this:

<user id="12345"> -- data should within user tag   <user_type>student</user_type>   <name_first>jane</name_first>   <name_last>smith</name_last>   <email>jsmith@somedomain.com</email>   <transcript> -- course data should within transcript tag     <course id="abc123">       <title>accounting 101</title>       <credits>3.0000</credits>       <grade>b</grade>     </course>     <course id="eng151">       <title>english 151</title>       <credits>3.0000</credits>       <grade>a</grade>     </course>     <course id="mat102">       <title>math 102</title>       <credits>3.0000</credits>       <grade>b</grade>     </course>   </transcript> </user> 

if there more information can provide, let me know. thank in advance help!

select top 5 user_type, name_first, name_last users xml auto, root('user'), elements 

adding user root places other elements underneath it. hope helps!


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -