Build XML

0

Please login or register to vote for this query.

(click on this box to dismiss)

スタック・オーバーフロー

プログラマーとプログラミングに熱心な人々のための質問と回答

declare @T table(id int, name varchar(20))

insert into @T values(321, 'Book')
insert into @T values(654, 'Pen')

select (
         select 'id' as '@name',
                T.id as '@value'
         for xml path('column'), type
       ),
       (
         select 'name' as '@name',
                T.name as '@value'
         for xml path('column'), type
       )
from @T as T
for xml path('row'), root('root')

Enter Parameters

Options:
Switch to meta site
loading Hold tight while we fetch your results