I have json data which have a list of productDetails. I need to combine each of the detail with productId.
I am using a stored procedure. This is my code:
DECLARE @products AS TABLE(productName NVARCHAR(255),
productId INT NOT NULL);
INSERT INTO @products
EXEC [saveproducts] @product;
From the above query, I will get the list of products as a table. Now I need to join the detail in the json with corresponding product
INSERT INTO @detail
SELECT
[detaiId], [productId]
FROM
OPENJSON(@detailJSON)
WITH(detailId UNIQUEIDENTIFIER 'strict $.detaiId',
productId INT ??????);
How to get the productId by comparing the productName in @detailJSON and from table @products?