Build XML

0

Please login or register to vote for this query.

(click on this box to dismiss)

Ask Different

Q&A for power users of Apple hardware and software

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