Skip to content
Advertisement

SQL Server: Update table based on JSON

I am trying to update rows in table based on JSON I have. JSON has the following structure:

Table dbo.sensors has same structure + few more columns. To insert such JSON object, not array, into table, I would do it this way:

So I have 2 questions: how to iterate over each element in JSON array and update each row with the same id. Any help would be appreciated:)

Advertisement

Answer

First, read documentation OPENJSON. This feature is available starting version 2016.
Next, apply new knowledge.

You can use result (rowset) as it is a table.

Advertisement