Skip to content
Advertisement

How to loop through JSON array to insert rows in SQL Table using TSQL?

I have following query where I would like to insert data from JSON:

Now I would like to have loop kind of structure so that I can insert second element 1 then third lement [2] and so on..

And so on…

JSON data stored in the SQL table where the column name is record:

Image of record column where JSON objects stored: enter image description here

Advertisement

Answer

Here is how you can parse your JSON to be inserted into your table:

Returns

Note that some column values will be duplicated given meta, extension, and identifier contain arrays.

UPDATE

To run against a table column do the following:

INSERT EXAMPLE

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement