sqlsql-serversql-server-2014

Replace specific character from all rows in database column


I've updated a Database and there was an issue with the Excel sheet which added ? instead of ° to all items of one column. The column is called Chemical and its in a table called ChemicalResistance.

Does anybody have an idea how to change this in SQL rather than having to change the whole excel sheet, row by row?

I thought of using REPLACE but couldn't get it to work and I'm quite new to SQL


Solution

  • update ChemicalResistance
      set Chemical = replace(Chemical,'?','°')
    

    BTW, if only a smaller part of the rows contains that character to replace, it could be a good idea to keep the transaction size down by adding a WHERE clause. Simply add the following at the end of the UPDATE statement:

    where CHARINDEX('?', Chemical) > 0