简体   繁体   English

SQL“用于XML”和诸如“ comment()”之类的内置函数

[英]SQL “for XML” and built-in functions like “comment()”

I'm writing an SQL select statement which returns XML. 我正在写一个返回XML的SQL select语句。 I wanted to put in some comments and found a post asking how to do this. 我想发表一些评论,并找到一条帖子询问如何执行此操作。 The answer seemed to be the "comment()" function/keyword. 答案似乎是“ comment()”函数/关键字。 So, my code looks broadly like this: 因此,我的代码大致如下所示:

select  ' extracted on tuesday ' as 'comment()',
        (select top 5 id from MyTable for xml path(''),type)
for xml path('stuff')

...which returns XML as follows: ...返回XML,如下所示:

<stuff>
  <!-- extracted on tuesday -->
  <id>0DAD4B42-CED6-4A68-AB7D-0003E4C127CC</id>
  <id>24BD0E5F-8B76-43FF-AEEA-0008AA911ADD</id>
  <id>AAFF5BB0-BFFB-4584-BACC-0009684A1593</id>
  <id>0581AF24-8C30-408C-9A48-000A488133AC</id>
  <id>01E2306D-296A-4FF7-9263-000EEFF42230</id>
</stuff>

In the process of trying to find out more about "comment()", I discovered "data()" as well. 在尝试查找有关“ comment()”的更多信息的过程中,我还发现了“ data()”。

select top 5 id as 'data()' from MyTable for xml path('')

Unfortunately, the names make searching for information on these functions very difficult. 不幸的是,这些名称使搜索有关这些功能的信息变得非常困难。

Can someone point me at the documentation on their usage, as well as any other similar functions ? 有人可以向我指出有关其用法以及任何其他类似功能的文档吗?

Thanks, 谢谢,

Edit: 编辑:

Another would appear to be "processing-instruction(blah)". 另一个似乎是“处理指令(blah)”。

Example: 例:

select  'type="text/css" href="style.css"' as 'processing-instruction(xml-stylesheet)',
        (select top 5 id from MyTable for xml path(''),type)
for xml path('stuff')

Results: 结果:

<stuff>
  <?xml-stylesheet type="text/css" href="style.css"?>
  <id>0DAD4B42-CED6-4A68-AB7D-0003E4C127CC</id>
  <id>24BD0E5F-8B76-43FF-AEEA-0008AA911ADD</id>
  <id>AAFF5BB0-BFFB-4584-BACC-0009684A1593</id>
  <id>0581AF24-8C30-408C-9A48-000A488133AC</id>
  <id>01E2306D-296A-4FF7-9263-000EEFF42230</id>
</stuff>

Here is the link to the BOL info: Columns with the Name of an XPath Node Test . 这是指向BOL信息的链接: 带有XPath Node Test名称的列 This details the functionality you are interested in. (It can indeed be a pain to find) 这详细说明了您感兴趣的功能。(确实很难找到)

Also you can find quick functional examples here 您也可以在这里找到快速的功能示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM