联机丛书上是这么说滴:
[ FOR { BROWSE | <XML> } ]
<XML> ::=
XML 
    { 
      { RAW [ ('ElementName') ] | AUTO } 
        [ 
           <CommonDirectives> 
           [ , { XMLDATA | XMLSCHEMA [ ('TargetNameSpaceURI') ]} ] 
           [ , ELEMENTS [ XSINIL | ABSENT ] 
        ]
      | EXPLICIT 
        [ 
           <CommonDirectives> 
           [ , XMLDATA ] 
        ]
      | PATH [ ('ElementName') ] 
        [ 
           <CommonDirectives> 
           [ , ELEMENTS [ XSINIL | ABSENT ] ]
        ]
     } 
 
 <CommonDirectives> ::= 
   [ , BINARY BASE64 ]
   [ , TYPE ]
   [ , ROOT [ ('RootName') ] ]PATH 
提供一种更简单的方式来混合元素和属性,并引入表示复杂属性的其他嵌套。可以使用 FOR XML EXPLICIT 模式查询从行集中构造这种 XML,但 PATH 模式针对可能很烦琐的 EXPLICIT 模式查询提供了一种更简单的替代方式。通过 PATH 模式,以及用于编写嵌套 FOR XML 查询的功能和返回 xml 类型实例的 TYPE 指令,您可以编写简单的查询。它为编写大多数 EXPLICIT 模式查询提供了一个替代方式。默认情况下,PATH 模式为结果集中的每一行生成一个 <row> 元素包装。您还可以选择指定元素名称。如果这样,则指定的名称用作包装元素名称。如果提供空字符串 (FOR XML PATH ('')),则不会生成任何包装元素。有关详细信息,请参阅使用 PATH 模式。

解决方案 »

  1.   

    没有语法错误,参考:http://blog.csdn.net/dobear_0922/archive/2008/04/22/2313839.aspx
      

  2.   

    if object_id('tempdb..#') is not null
    drop table #
    create table #(TrunkID  int,
    Carrier varchar(30))
    insert into #
    select 123,'andy'
    union all
    select 879,'judy'
    union all
    select 355,'andy'
    union all
    select 676,'judy'
    union all
    select 7867,'andy'
    select * from #select Carrier
    ,TrunkID =(stuff((
    select  ','+ltrim(TrunkID) 
    from # 
    where Carrier=b.Carrier
    for xml path('')
    )
    ,1,1,''))
     from #  b
    group by Carrier