Ok, not sure if this is possible to do..
I have a query that returns just simple records from the database, but formatted out as XML as follows:
select name, address, dateCreated, flag
from table
where name = 'test'
for xml path('row'), root('rows')
ok, no problems, and I get the XML as desired:
<rows>
<row>
<name>jddjdjd</name>
<address>dkdkdkdkdkd</address>
.. and so on...
</row>
</rows>
BUT WHAT I AM TRYING TO FIND OUT IS
If I can have the XML return as follows:
<rows>
<row id='@@rowcount'>
<name>jddjdjd</name>
<address>dkdkdkdkdkd</address>
.. and so on...
</row>
</rows>
As you can see, I really could do with the node returning with an attribute of say a @@rowcount or even a field from the select statement (not sure if that is possible!!)
Any help much appreciated!!!
David.
You could alias
@@rowcountto'@id', like:This prints:
However, I’m not sure it’s clearly defined what
@@rowcountmeans at the point where it gets turned into an attribute.