I have such a question - there are 2 tables in which you need to transfer data from XML of this format:

<t1> <t2> <val>10</val> <t3>100</t3> <t3>200</t3> </t2> <t2> <val>20</val> <t3>100</t3> </t2> </t1> 

the data from the val block must go to table t1, column v, and the data from t3 to table t2, column v2.

I have an idea so far very cumbersome and not very working because when v2 is added to t2, the values ​​are confused and the wrong id is assigned to them:

 INSERT INTO t1 (v) SELECT Tbl.Col.value('val[1]', 'int') FROM @xml.nodes('//t2') Tbl(Col) INSERT INTO t3 (v2) SELECT Tbl.Col.value('t3[1]', 'int') FROM @xml.nodes('//t2') Tbl(Col) UNION ALL SELECT Tbl.Col.value('t3[2]', 'int') FROM @xml.nodes('//t2') Tbl(Col) 

There are no ideas so far, so I hope for your revenue.

    0