次の方法で共有


XQuery のコメント

XQuery にはコメントを追加できます。"(:" と ":)" を区切り記号として使用することで、コメント文字列が追加されます。次に例を示します。

declare @x xml
set @x=''
SELECT @x.query('
(: simple query to construct an element :)
<ProductModel ProductModelID="10" />
')

次に、xml 型の Instruction 列に対してクエリが指定されている別の例を示します。

SELECT Instructions.query('
(: declare prefix and namespace binding in the prolog. :)
     declare namespace AWMI="https://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelManuInstructions";
  (: Following expression retrieves the <Location> element children of the <root> element. :)
  /AWMI:root/AWMI:Location
') as Result
FROM Production.ProductModel
where ProductModelID=7