将唯一行计数添加到 SQL 2008“for xml 路径”陈述?
好的,不确定这是否可行。
我有一个查询,它仅从数据库返回简单的记录,但格式为 XML,如下所示:
select name, address, dateCreated, flag
from table
where name = 'test'
for xml path('row'), root('rows')
好的,没问题,我得到了所需的 XML:
<rows>
<row>
<name>jddjdjd</name>
<address>dkdkdkdkdkd</address>
.. and so on...
</row>
</rows>
< strong>但是我想找出的是
如果我可以按如下所示返回 XML:
<rows>
<row id='@@rowcount'>
<name>jddjdjd</name>
<address>dkdkdkdkdkd</address>
.. and so on...
</row>
</rows>
正如您所看到的,我确实可以使用返回一个 @@ 属性的节点来实现rowcount 甚至是 select 语句中的字段(不确定这是否可能!!)
非常感谢任何帮助! 大卫.
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以将
@@rowcount
别名为'@id'
,例如:这会打印:
但是,我不确定是否明确定义了
@@rowcount
code> 表示它转变为属性的位置。You could alias
@@rowcount
to'@id'
, like:This prints:
However, I'm not sure it's clearly defined what
@@rowcount
means at the point where it gets turned into an attribute.