Skip to content
Advertisement

Detect duplicate JSON nodes in JSON parameter before insert in SQL Server table

I want to detect duplicate nodes from JSON before insert them in SQL Server table.

I have this stored procedure that takes a JSON parameter like this:

I want to return exception if @SalaryItems has duplicate key

How can I detect

duplicate in this table in my code?

Advertisement

Answer

Use OPENJSON() without a with clause so that it returns the raw key, value and type columns, e.g.:

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