Concatenate XML variables in SQL Server

pecarudibuveh

New Member
I have a query in a stored procedure retrieving some data in XML format to be returned in a variable \[code\]@xml_data\[/code\], like this:\[code\]SELECT @xml_data = http://stackoverflow.com/questions/12786865/( SELECT * FROM ( SELECT 1 AS Tag ,0 AS Parent ..... FROM MyTable WHERE id = @id UNION ALL SELECT 2 AS Tag ,1 AS Parent .... FROM MyTable2 WHERE id = @id UNION ALL SELECT 3 AS Tag ,2 AS Parent .... FROM MyTable3 WHERE id = @id ) resultsFOR XML EXPLICIT, TYPE)\[/code\]This is working like the proverbial dream :)However, I'd like to concatenate a header to this XML (e.g. \[code\]<xml version="1.0" encoding="ISO-8859-1"/>\[/code\]) and can't figure out how to do it. I've tried converting to \[code\]NVARCHAR\[/code\], selecting the two variables in one statement but can't seem to get it right. Can anyone help??Thanks :)
 
Back
Top