2017-03-03 7 views
2

SQL Server 2000(互換性レベル= 80)およびSQL Server 2008(互換性レベル= 100)の同じxml出力を生成する方法はありますか。SQL Server 2000および2008のXML autoを使用した異なるXML結果

例:

create table #temp(a int, b varchar(10)) 

insert into #temp 
select 1, 'abc' 
union 
select 1,'def' 

select * 
from 
    (select * from #temp child) parent 
for xml auto, elements 

SQL Server 2000の(互換性レベル80)のための出力:SQL Server 2008の

<child> 
     <a>1</a> 
     <b>abc</b> 
</child> 
<child> 
     <a>1</a> 
     <b>def</b> 
</child> 

出力(互換性レベル100):

<parent> 
      <a>1</a> 
      <b>abc</b> 
    </parent> 
    <parent> 
      <a>1</a> 
      <b>def</b> 
    </parent> 

感謝

+0

:行く、これまで可能であればアップグレードのために。 2000年はもうサポートされていません(かなりの期間)。利点と新機能は、ほとんどの場合、価値があります。 – Shnugo

答えて

0

parentでエイリアスchildを交換することはトリックを行う必要があります。

create table #temp(a int, b varchar(10)) 

insert into #temp 
select 1, 'abc' 
union 
select 1,'def' 

select * 
from 
    (select * from #temp parent) parent 
for xml auto, elements 

私は両方のケースで結果が互換性レベル80と100と、このクエリを試してみました:オフトピック

<parent> 
    <a>1</a> 
    <b>abc</b> 
</parent> 
<parent> 
    <a>1</a> 
    <b>def</b> 
</parent> 
関連する問題