SQL to update part of data field

Posted on

Question :

I am looking to put an SQL update statement together to remove an ampersand sign (&) for customer names – I need to replace it with the word ‘and’.

This will be for multiple customer records.


Answer :

Without knowing a bit more about the data structure and which server you’re using it is difficult to suggest an answer. If you’re using Microsoft’s SQL Server, you can look at using the REPLACE function. For example

UPDATE Customers
SET CustomerName = REPLACE(CustomerName, ' & ', ' and ')

I created a quick demo for you in SQL Fiddle.

Leave a Reply

Your email address will not be published. Required fields are marked *