sql server - Can the ROOT element in a select statement using FOR XML PATH be set using a variable? -
i have query creates xml file. currently, have root element hard-coded. use variable value set root element value substituting hard-coded string variable throws syntax error of expecting string
. select statement:
declare @selectresults xml declare @databasename varchar(100) select @databasename = db_name(); set @selectresults = ( select...query results here... xml path(''), root(@databasename) --when set 'databasename' works )
can use variable in function root()
?
you replacement in separate replace acting on xml output:
declare @selectresults xml declare @databasename varchar(100) select @databasename = db_name(); set @selectresults = replace( select...query results here... xml path(''), root('root_element') --when set 'databasename' works ), 'root_element>',@databasename+'>' )
Comments
Post a Comment