Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove all apostrophes in field with T-SQL

I have a value in database and it contains a few apostrophes like...........

It's a good day. He's so happy.

Result must be.....

Its a good day. Hes so happy.

What T-SQL statement can I use to remove the apostrohe?

like image 838
Etienne Avatar asked Dec 12 '22 01:12

Etienne


2 Answers

Use replace, here's an example:

declare @value varchar(40)
select @value = 'It''s a good day. He''s so happy.'


select @value, replace(@value, '''', '')

If you want to update a column in a table, do it like this:

update table
set column = replace(column, '''', '')

It replaces all occurrences of a specified string value (in your case apostrophes) with another string value (in your case empty string).

like image 149
aF. Avatar answered Jan 31 '23 07:01

aF.


Use:

REPLACE ( string_expression , string_pattern , string_replacement )
like image 36
Kapil Khandelwal Avatar answered Jan 31 '23 07:01

Kapil Khandelwal