共用方式為


XQuery 中的註解

適用於:SQL Server

您可以將批註新增至 XQuery。 透過使用 (::) 分隔符來新增註解字串。 例如:

DECLARE @x AS XML;
SET @x = '';

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

以下範例展示了對 InstructionsXML 欄位的查詢:

SELECT Instructions.query('
(: declare prefix and namespace binding in the prolog. :)
     declare namespace AWMI = "http://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;