Skip to content
Advertisement

Is there an UPDATE equivalent command to SELECT json data

Is there a way to update the data retrieved from the below select (in this case, change “MS220” to something else)? It’s difficult enough to do select from JSON in some cases. I’m not sure how to update just a single element.

Advertisement

Answer

Try JSON_MODIFY() with the path '$[0].Name'

Results:

[
    {
        "Categories": [
            {
                "QuerySourceNames": [
                    "QAsset"
                ],
                "Id": "eceae85a-ffc6-49f4-8f6a-78ce2b4b274e",
                "Name": "emsdba"
            }
        ],
        "Id": "525b4f07-0f67-43ac-8070-a0e6c1ceb1b9",
        "Name": "New Value"
    }
]

db<>fiddle here

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement