SQL Replace and Previewing your Changes
Recently I had a situation where I needed to a full url to a relative url in the database. I just needed to remove the domain portion of the path, but I wanted to preview it live before I executed the query. Here's the solution for the preview and for the actual update statement.
select replace(<column_name>,'original_string','new_string') from <table_name> where <column_name> like ‘%the string you want to replace%’
update <table_name> set <column_name> = replace(<column_name>,'original_string','new_string') where <column_name> like ‘%the string you want to replace%’
0 comments