以萬用字元 (*) 指定名稱的資料行Columns with a Name Specified as a Wildcard Character

適用範圍:Applies to: 是SQL ServerSQL Server (所有支援的版本) yesSQL ServerSQL Server (all supported versions) 是Azure SQL DatabaseAzure SQL DatabaseYesAzure SQL DatabaseAzure SQL Database適用範圍:Applies to: 是SQL ServerSQL Server (所有支援的版本) yesSQL ServerSQL Server (all supported versions) 是Azure SQL DatabaseAzure SQL DatabaseYesAzure SQL DatabaseAzure SQL Database

如果以萬用字元 (*) 指定資料行名稱,則插入該資料行內容的方式,就像是沒有指定資料行名稱一樣。If the column name specified is a wildcard character (*), the content of that column is inserted as if there is no column name specified. 如果此資料行是非 xml 類型的資料行,則會以文字節點插入資料行內容,如下列範例所示:If this column is a non-xml type column, the column content is inserted as a text node, as shown in the following example:

USE AdventureWorks2012;  
GO  
SELECT E.BusinessEntityID "@EmpID",   
       FirstName "*",   
       MiddleName "*",   
       LastName "*"  
FROM   HumanResources.Employee AS E  
  INNER JOIN Person.Person AS P  
    ON E.BusinessEntityID = P.BusinessEntityID  
WHERE E.BusinessEntityID=1  
FOR XML PATH;  

以下是結果:This is the result:

<row EmpID="1">KenJSánchez</row>

如果此資料行是 xml 類型,就會插入對應的 XML 樹狀結構。If the column is of xml type, the corresponding XML tree is inserted. 例如,下列查詢為資料行名稱指定 "*",該資料行名稱包含 XQuery 針對 Instructions 資料行所傳回的 XML。For example, the following query specifies "*" for the column name that contains the XML returned by the XQuery against the Instructions column.

SELECT   
       ProductModelID,  
       Name,  
       Instructions.query('declare namespace MI="https://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelManuInstructions"  
                /MI:root/MI:Location   
              ') as "*"  
FROM Production.ProductModel  
WHERE ProductModelID=7  
FOR XML PATH;   

以下是結果。This is the result. 插入 XQuery 所傳回的 XML,但不會有包裝元素。The XML returned by XQuery is inserted without a wrapping element.

<row>
  <ProductModelID>7</ProductModelID>
  <Name>HL Touring Frame</Name>
  <MI:Location LocationID="10">...</MI:Location>
  <MI:Location LocationID="20">...</MI:Location>
  ...
</row>

另請參閱See Also

搭配 FOR XML 使用 PATH 模式Use PATH Mode with FOR XML