名称指定为通配符的列

如果指定的列名是通配符 {,则插入该列的内容,就好像没有指定列名一样。 如果此列是非xml 类型列,则列内容将作为文本节点插入,如以下示例所示:

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;  

结果如下:

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

如果列的类型为 xml 类型,则插入相应的 XML 树。 例如,以下查询为列名称指定“*”,该列名称包含 XQuery 针对指令列返回的 XML。

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;   
GO  

结果如下: XQuery 返回的 XML 插入时不带包装元素。

<row>

<ProductModelID>7</ProductModelID>

<Name>HL Touring Frame</Name>

<MI:Location LocationID="10">...</MI:Location>

<MI:Location LocationID="20">...</MI:Location>

...

</row>

另请参阅

将 PATH 模式与 FOR XML 配合使用