Link to home
Start Free TrialLog in
Avatar of cgcmq
cgcmqFlag for Canada

asked on

Using a variable in path name FOR XML PATH

Is it possible to use a variable that has been declared in the query for the path name in FOR XML PATH?

For example, I have a variable
  @Section varchar(100)

How can I use this as the root name in XML PATH:
  FOR XML PATH('Products'), ROOT(@Section)

I am using SQL Server 2005
Avatar of cgcmq

ASKER

None of those links addressed the issue of using a variable as the name of a node in XML PATH.  I suspect that it may simply be a matter of the correct syntax within a stored procedure to replace 
    FOR XML PATH('Products'), ROOT('name of this node')
with:
    FOR XML PATH('Products'), ROOT(@Section)
ASKER CERTIFIED SOLUTION
Avatar of Mark Wills
Mark Wills
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of cgcmq

ASKER

Sorry for the delay - I was out of town for several days.