Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you strip a character out of a column in SQL Server?

Tags:

sql

sql-server

How do you remove a value out of a string in SQL Server?

like image 612
Even Mien Avatar asked Jun 11 '09 20:06

Even Mien


People also ask

How do I remove one character from the left in SQL?

Syntax: SELECT SUBSTRING(column_name,2,length(column_name)) FROM table_name; To delete the first character from the FIRSTNAME column from the geeks for geeks table.


1 Answers

This is done using the REPLACE function

To strip out "somestring" from "SomeColumn" in "SomeTable" in the SELECT query:

SELECT REPLACE([SomeColumn],'somestring','') AS [SomeColumn]  FROM [SomeTable] 

To update the table and strip out "somestring" from "SomeColumn" in "SomeTable"

UPDATE [SomeTable] SET [SomeColumn] = REPLACE([SomeColumn], 'somestring', '') 
like image 157
Jose Basilio Avatar answered Sep 20 '22 06:09

Jose Basilio