I have a table with column named "Description". Value of each record has json array format. Suppose value of two records are:
[
{"languageCode":"fr","description":"France","isDefault":true},
{"languageCode":"cs","description":"Czech","isDefault":false},
{"languageCode":"it-IT","description":"Italian","isDefault":false}
]
and
[
{"languageCode":"cs","description":"Czech","isDefault":false},
{"languageCode":"it-IT","description":"Italian","isDefault":false},
{"languageCode":"fr-FR","description":"France","isDefault":true}
]
I want update all records of table and update value of languageCode if it is "fr" and "cs" to "fr-FR" and "cs-CZ"
Expected:
[
{"languageCode":"fr-FR","description":"France","isDefault":true},
{"languageCode":"cs-CZ","description":"Czech","isDefault":false},
{"languageCode":"it-IT","description":"Italian","isDefault":false}
]
and
[
{"languageCode":"cs-CZ","description":"Czech","isDefault":false},
{"languageCode":"it-IT","description":"Italian","isDefault":false},
{"languageCode":"fr-FR","description":"France","isDefault":true}
]
I tried Update table and set Description column but I don't know how to find languages code (fr, cs) and update it.
Updated: I change my approach by use REPLACE instead through json But I think Json still is a good approach.
Here is my script
UPDATE applications
SET Description = REPLACE ( REPLACE ( Description, '\"languageCode\":\"fr\"', '\"languageCode\":\"fr-FR\"'), '\"languageCode\":\"cs\"', '\"languageCode\":\"cs-CZ\"')