SQL Server 2008 R2 には、次のような有効な XML ノード (1 つの列、xml 型) の行を含むテーブルがあります。
create table #t (x xml not null);
insert into #t
values ('<service><value1>stuff</value1><value2>more stuff</value2></service>')
, ('<service><value1>I am a different row</value1><value2>more stuff</value2></service>');
これらを 1 つの XML BLOB に選択したいと思います。
<services>
<service>. . .</service>
<service>. . .</service>
</services>
これを試すために FOR XML PATH を使用していますが、「サービス」ノードの周りにノードとして列ヘッダー「x」が埋め込まれています。
select x
from #t
for XML PATH(''), ROOT('services')
これにより、次が生成されます。
<services>
<x><service>. . .</service></x>
<x><service>. . .</service></x>
</services>
「x」ノードを取り除くにはどうすればよいですか?
select x as "" と select x as "." を試してみました。しかし、これらは予約語であり、クエリでエラーが発生します。