Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Replace a specific string value

Lets say I have this table

+-------+--------------------------------------------------------------------------+
| id    | json_text                                                                |
+-------+--------------------------------------------------------------------------+
| aWoJl | {"color":"#1B3451","help_text":"color is here but dont replace me"}      |
+-------+--------------------------------------------------------------------------+
| r5Njc | {"color":"#1B3451","help_text":"color is also here but dont replace me"} |
+-------+--------------------------------------------------------------------------+

Now I want to change color value from #1B3451 to #1e72d2. How can I do that?

I have tried using replace(), but no result as of now and when trying to use wildcards, it is throwing error.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Here is the SQL fiddle .
http://sqlfiddle.com/#!18/6db3f9/1

>Solution :

You have to convert first to VARCHAR or NVARCHAR then REPLACE

UPDATE temptable set [json_text] = REPLACE(CAST([json_text] AS NVARCHAR(MAX)),N'#1B3451',N'#1e72d2');
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading