I tried to create a stored procedure to insert data by JSON and Parameter
Declare @PaymentJson Nvarchar(1000) = N'{"type":4},{"type":1`},{"type":2},{"type":3}'
,@ProductID bigint = 5
,@UserCode bigint = 2
Insert into PaymentType ([ProductID], [PaymentType],[UserCode])
SELECT @ProductID,
PaymentType = MAX(CASE WHEN LOWER([key]) = 'type' THEN [value] END),
@UserCode
FROM OPENJSON(@PaymentJson)
Result is not true, is 1 first JSON (in this case type is 4) row.
(1 row affected)
I need, the required number of JSON strings , insert into row PaymentType in this case should be:
(4 row affected)
ProductID PaymentType UserCode
5 4 2
5 1 2
5 2 2
5 3 2
My DBMS is SQL Server 2019