0

I have below table. I want this products table to be updated based on @source json

product_id, product_name,total_sales

enter image description here

OPENJSON gives me key and value , but how do i explicitly set column names for my json

and also while doing join i need to skip electronics then only it will do join

This code throws error as key not found

begin 
declare @source nvarchar(max) = '{"electronics.tv":200,"electronics.mobile":1000}'

 UPDATE p
 SET p.total_sales = u.value
 products p
 INNER JOIN 
 OPENJSON(@source,'$') AS u
 ON p.product_name = u.key

end 

It thows error as incorrect syntax near key

Can someone help me here

2
  • KEY is a reserved keyword, it must be delimit identified. Commented Aug 17, 2023 at 15:32
  • "how do i explicitly set column names for my json" In the WITH clause, such as shown in example 3 of the documentation Commented Aug 17, 2023 at 15:38

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.