Testtabel en gegevens
create table tableABC(A int, B bit, C varchar(10))
insert into tableABC values(1, 1, 'Row 1')
insert into tableABC values(2, 0, 'Row 1')
Download de xml
declare @xml xml
set @xml = (select *
from tableABC
for xml auto, elements)
XML-gegevens
<tableABC>
<A>1</A>
<B>1</B>
<C>Row 1</C>
</tableABC>
<tableABC>
<A>2</A>
<B>0</B>
<C>Row 1</C>
</tableABC>
Invoegen in een andere tabelABC
insert into tableABC(A, B, C)
select
r.value('A[1]', 'int'),
r.value('B[1]', 'bit'),
r.value('C[1]', 'varchar(10)')
from @xml.nodes('tableABC') t(r)
Bewerken Kopieer dit hele statement om te testen of het werkt
use tempdb
go
create table tableABC(A int, B bit, C varchar(10))
go
insert into tableABC values(1, 1, 'Row 1')
insert into tableABC values(2, 0, 'Row 1')
declare @xml xml
set @xml = (select *
from tableABC
for xml auto, elements)
insert into tableABC(A, B, C)
select
r.value('A[1]', 'int'),
r.value('B[1]', 'bit'),
r.value('C[1]', 'varchar(10)')
from @xml.nodes('tableABC') t(r)
select *
from tableABC
go
drop table tableABC
Resultaat is dubbele rijen in tableABC
A B C
----------- ----- ----------
1 1 Row 1
2 0 Row 1
1 1 Row 1
2 0 Row 1