标题:新人求教:for xml
只看楼主
jsntxzl
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2011-9-6
结帖率:0
 问题点数:0 回复次数:0 
新人求教:for xml
想达到以下效果,该如何安排表?查询语句怎样写?先谢了!
<?xml version="1.0" encoding="UTF-8"?>
<Document xmlns:xsi="http://www. xmlns:xsd="http://www. SN="000000000000" License="20081018-594044" Version="2.10">
  <Events>
    <Event Name="SalesWareHouseOut" MainAction="WareHouseOut">
      <DataField>
        <Data Code="81003350050092884560" Actor="1111" ActDate="2011-04-17"/>
        <Data Code="81003350050092875389" Actor="1111" ActDate="2011-04-17"/>
        <Data Code="81003350050092860920" Actor="1111" ActDate="2011-04-17"/>
      </DataField>
    </Event>
  </Events>
</Document>


我用以下查询
select 'http://www.' as 'xmlns:xsi',
       'http://www.' as 'xmlns:xsd',
       '000000000000' as SN,'20081018-594044' as License,'2.10' as Version,
(select
      (select 'SalesWareHouseOut' as name,'WareHouseOut' as MainAction,
              (select
                     (select * from Data
                         for xml auto,type)
                 for xml raw ('DataField'),type)
          for xml raw ('Event'),type)
for xml raw ('Events'), type)
for xml raw ('Document'),type

得到了如下结果:
<Document xmlns:xsi="http://www. xmlns:xsd="http://www. SN="000000000000" License="20081018-594044" Version="2.10">
  <Events>
    <Event Name="SalesWareHouseOut" MainAction="WareHouseOut">
      <DataField>
        <Data Code="81003350050092884560" Actor="1111" ActDate="2011-04-17"/>
        <Data Code="81003350050092875389" Actor="1111" ActDate="2011-04-17"/>
        <Data Code="81003350050092860920" Actor="1111" ActDate="2011-04-17"/>
      </DataField>
    </Event>
  </Events>
</Document>

但 <?xml version="1.0" encoding="UTF-8"?> 该怎么办?
另:如何在存储过程中将结果另存为文件?




[ 本帖最后由 jsntxzl 于 2011-9-7 09:14 编辑 ]
搜索更多相关主题的帖子: version 如何 
2011-09-06 11:24



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-349265-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014303 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved