Name XML result column of TSQL "for xml explicit"?
sql, sql-server, t-sql, xml
Solution
No, there is not, as far as I know. SQL Server Management Studio will autogenerate such a name for your XML.
You might be able to assign your output to an XML variable first and then select that to get a "nice" column name:
DECLARE @XmlResult XML
SELECT @XmlResult = ......
FROM .......
SELECT @XmlResult
but other than that, I'm not aware of any way to influence the name of the column generated by SSMS.
Marc
Problem
I have a query that uses `for xml explit` to return XML result. select ... from ... order by [BatchType!1!TypeName], [FormType!2!TypeName], Tag, Parent for xml explicit, root('ClientImages') But the name of resultant column name is something as cryptic as Is there a way to change the column name? [ANSWER] I had a several nested `WITH` statements so I have saved the result of query without applying `FOR XML EXPLICIT` into a temp table `@xmlTable` and then set the XML EXPLICIT result to an XML then returned it. ``` declare @xmlResult xml set @xmlResult =( select * from @xmlTable for xml explicit, root('ClientImages')) select @xmlResult as XmlResult ```