1

How do you set the root attribute to a column in a FOR XML in SQL Server?

For instance, if you have 3 columns like 'First Name', 'Last Name', and 'Person' and you wan the output to be something like

<root type="person">
    <first Name/>
    <last name/>
</root>

1 Answer 1

1

Try the following:

select 
    'person' as '@type'
    /*
    rest of stuff goes here...
    */
From someTable
FOR xml path('root')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.