One of the column I have, have values like this. If my JSON has key id then update its value to new one, if my JSON JSON has key workload then update its value to new one Like this, I have multiple entries to update with the new values.
Currently, I am trying to loop into the table, parsing one JSON value at a time. I have tried using CASE statements.
BEGIN
SET @MyCursor = CURSOR FOR
select key_value from @Template
where key_type = 5
OPEN @MyCursor
FETCH NEXT FROM @MyCursor
INTO @MyField
WHILE @@FETCH_STATUS = 0
BEGIN
update @Template
set key_value =
case
when 'id' in (select [key] from openjson(@MyField))
then
JSON_MODIFY(@MyField, '$.id', '1')
when 'workload' in (select [key] from openjson(@MyField))
then
JSON_MODIFY(@MyField, '$.workload', '5')
ELSE '3'
END
-- Fetch next
FETCH NEXT FROM @MyCursor
INTO @MyField
END;
CLOSE @MyCursor ;
DEALLOCATE @MyCursor;
END;
This gives the result as below
Please suggest what have I done wrong

