Search code examples
sqlsql-serverspecial-characters

Removing Special Characters SQL


I have a data set example here:

ShipName
FedEx International Economy®
FedEx Ground®
FedEx® International Connect Plus
FedEx International Priority®
FEDEX® INTERNATIONAL CONNECT PLUS
FedEx International Priority®
FEDEX INTERNATIONAL PRIORITY®

Yet, I want to remove all the special characters, so I can group them together appropriately. I realize I could just use UPPER(), however I need to remove them either way.

Because some of the characters are not on either end of the string, a simple Right() or Left() would not work.


Solution

  • It should be as simple as using the replace function on your column:

    select ShipName = replace(ShipName, '®', '')
      from Shipping
    

    SQL Fiddle: http://sqlfiddle.com/#!18/6f4d2/1

    Further reading: https://learn.microsoft.com/en-us/sql/t-sql/functions/replace-transact-sql?view=sql-server-ver16