XML Sql Iteration

I am trying to read an xml data field from a table and paste this data into another database. The XML document is as follows:

<Master> <UserIds> <id>1</id> <id>2</id> <id>3</id> <id>4</id> </UserIds> </Master> 

My idea was to get 1 id and paste, get another and paste it, and so on. I tried using xquery, but it is best to get all the data together, but I need to insert the id: /

Any help? D:

+4
source share
2 answers
 declare @xml xml = '<Master> <UserIds> <id>1</id> <id>2</id> <id>3</id> <id>4</id> </UserIds> </Master> ' insert into YourTable(ID) select TNvalue('.', 'int') from @xml.nodes('/Master/UserIds/id') as T(N) 
0
source
 DECLARE @x xml SET @x = '<Master> <UserIds> <id>1</id> <id>2</id> <id>3</id> <id>4</id> </UserIds> </Master>' INSERT TableName SELECT Tcvalue('.', 'int' ) FROM @x.nodes('//id') T(c) 
+1
source

Source: https://habr.com/ru/post/1383968/


All Articles