表(t1):
         a  b  c
第一行   1  2  3
第二行   4  5  6
第三行   7  8  9我想要导出xml形式是:  (以a列为节点名)
<t1>
<1 b="2" c="3"></1>
<4 b="5" c="6"></4>
<7 b="8" c="9"></7>
</t1>试了很多方法
select a,b,c from t1 for xml auto  这样只能导出以表名为节点名的形式  请问: 怎样才能生成以查询结果中的一列 为节点名呢?

解决方案 »

  1.   

    你这个只有用字符穿拼接方式,然后转换成xml例如declare @t table (id int IDENTITY(1,1),a int ,b int ,c int)
    insert into @t
    select 1,2,3 union all
    select 4,5,6 union all
    select 7,8,9
    declare @str nvarchar(max)
    set @str=''
    select @str=@str+'<'+cast(a as varchar(4))
    +' a="'+cast(a as varchar(4))
    +'" b="'+cast(b as varchar(4))
    +'" c="'+cast(c as varchar(4))+'"></'+cast(a as varchar(4))+'>' from @t
    select '<t1>'+@str+'</t1>' 
      

  2.   

    请参阅
    http://topic.csdn.net/t/20050811/17/4203524.html