I have a table which needs to be converted into XML however using the same XML element name concatinates the string of every column that tries to use it.
SELECT
SKU [SKU]
, title [Title]
, URL [URL]
, promotionsURL1 [PROMOTIONS/URL]
, promotionsURL2 [PROMOTIONS/URL]
, promotionsURL3 [PROMOTIONS/URL]
, promotionsURL4 [PROMOTIONS/URL]
, promotionsURL5 [PROMOTIONS/URL]
, promotionsURL6 [PROMOTIONS/URL]
FROM tblSLIRecommendations
FOR XML PATH('SKU_TO_TUNE'), ROOT('RECOMMENDATION_TUNINGS')
This gives me the XML result
<SKU_TO_TUNE>
<SKU>VS4111-546U135-U135</SKU>
<Title>Twirly Swiggles</Title>
<URL>http://www.sweetcandy.com/c-p/VS4111-546U135-U135</URL>
<PROMOTIONS>
<URL>http://www.sweetcandy.com/c-p/SA4211-472U135-U135http://www.sweetcandy.com/c-p/RK0179-000P143-P143http://www.sweetcandy.com/c-p/WJ4038-477U135-U135http://www.sweetcandy.com/c-p/HH3577-209U136-U136</URL>
</PROMOTIONS>
</SKU_TO_TUNE>
Whereas I would prefer the output like this but without needing the numbers after URL
<SKU_TO_TUNE>
<SKU>VS4111-546U135-U135</SKU>
<Title>Twirly Swiggles</Title>
<URL>http://www.sweetcandy.com/c-p/VS4111-546U135-U135</URL>
<PROMOTIONS>
<URL1>http://www.sweetcandy.com/c-p/SA4211-472U135-U135</URL1>
<URL2>http://www.sweetcandy.com/c-p/RK0179-000P143-P143</URL2>
<URL3>http://www.sweetcandy.com/c-p/WJ4038-477U135-U135</URL3>
<URL4>http://www.sweetcandy.com/c-p/HH3577-209U136-U136</URL4>
</PROMOTIONS>
</SKU_TO_TUNE>
Is there a simple way to get round this?