新人求教: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 编辑 ]