I have a requirement to return xml as follow
<row id="1">
<cell>1</cell>
<cell>setup/pagemst</cell>
<cell>Page Master</cell>
</row>
<row id="2">
<cell>2</cell>
<cell>setup/modules</cell>
<cell>Module Master</cell>
</row>
I used the following Query but it does not work
select
pageid id,pgurl cell,pgname cell
from m_pages
for xml raw
The same column names for all columns works fine in oracle but not in SQL Server 2005. Any Ideas ?
Thanks in advance
deb
Use the
FOR XML PATHsyntax available in SQL Server 2005 and newer – try something like this:Gives me the output in the end:
The
FOR XML PATHsyntax allows you to define what values to return as XML attributes (... AS '@id') or XML elements. By adding “empty” lines between the elements, you prevent the output from being merged / concatenatedinto a single
<cell>....</cell>XML element