Skip to content
Advertisement

Compare between JSON string using openjson in SQL Server 2016

I have two scenarios of inserting json string. I check the json string is already exists or not using the below code and then I insert into the table

In the 2nd Scenario, my data is not getting inserted into table as the count is 1. But I want both the string in scenario 1 and 2 to be treated as different and both the data to be inserted into database.

Advertisement

Answer

I think the best solution here is actually to use JSON_QUERY instead of JSON_VALUE, since your keys may be dynamic. Once you switch to JSON_QUERY, you no longer need to execute dynamic SQL.

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