Suppose we have ID, FirstName and LastName columns in one of our SQL Server table and we want output something like this:
Let me give you TSQL to generate table in SQL Server and insert records in that.
Create Table EmployeeData
So now, here is the use of “FOR XML PATH ROOT” clause which will make our life easier in this kind of situation.
select ID as "ID/@value"
Isn’t it easy to use?
BTW, below given are some links which will redirect you to my some of the past articles on XML subject.
Load relational XML data
Read XML node on same level
Return comma separated value with “For XML Path”
update UnTyped XML data column
Reference: Ritesh Shah
Note: Microsoft Books online is a default reference of all articles but examples and explanations prepared by Ritesh Shah, founder of http://www.SQLHub.com