I am manipulating a JSON column in an Azure SQL table / database, the JSON object is formed as follows:
{ "statusId": "5A5BC717-F33A-42A5-8E48-99531C30EC87", "creationDateTime": "", "assignations": [ { "userId": "CA3B0589-B558-4FCC-93A6-560754D324FC", "dateTime": "", "isCurrentAssigned": false }, { "userId": "CA3B0589-B558-4FCC-93A6-560754D325E8", "dateTime": "", "isCurrentAssigned": false }, { "userId": "CA3B0589-B558-4FCC-93A6-560754D347N", "dateTime": "", "isCurrentAssigned": true } ] }
What I want to do is find a specific element inside the "destination" array and then update some of its properties, just something like:
UPDATE MyTable SET JsonData = JSON_MODIFY(JsonData, '$.assignations.isCurrentAssigned', CONVERT(BIT, 0)) FROM MyDb WHERE JSON_VALUE(JsonData, '$.assignations.isCurrentAssigned') = CONVERT(BIT, 1) AND JSON_VALUE(JsonData, '$.assignations.userId') = CONVERT(UNIQUEIDENTIFIER, 'CA3B0589-B558-4FCC-93A6-560754D347N')
Of course, this T-SQL is not working, I would appreciate any help with this
source share