siddhesh
siddhesh

Reputation: 41

Remove special character from customerId column in SQL Server

I want remove special character from CustomerId column.

Currently CustomerId column contains ¬78254782 and I want to remove the ¬ character.

Could you please help me with that ?

enter image description here

Upvotes: 0

Views: 2442

Answers (2)

masoud rafiee
masoud rafiee

Reputation: 447

Applying the REPLACE T-SQL function :

SELECT REPLACE(CustomerId, '¬', '') FROM Customers;

Upvotes: 4

Tim Biegeleisen
Tim Biegeleisen

Reputation: 522626

SQL Server does not really have any regex support, which is what you would probably want to be using here. That being said, you could try using the enhanced LIKE operator as follows:

UPDATE yourTable
SET CustomerId = RIGHT(CustomerId, LEN(CustomerId) - 1)
WHERE CustomerId LIKE '[^A-Za-z0-9]%';

Here we are phrasing the condition of the first character being special using [^A-Za-z0-9], followed by anything else. In that case, we substring off the first character in the update.

Upvotes: 2

Related Questions