Fatih Yavuz Fatih Yavuz - 2 months ago 22
SQL Question

Changing two spaces to one space in a column through sql

I have a table that have two columns. First column is 'Word' column. Second column is 'Descripton' column. There are some records that have two spaces in Word column. I'd like to change two sequent spaces to one space. For example "Hello World" to "Hello World".

In Description column, some records contain turkish characters as html codes. For example 'Öay' instead of '├žay'. I want to change them to actual turkish characters.

I can do that by reading the table line by line with php but I'm wondering if there is an easy way to do that with sql.

Answer

You can use the REPLACE function like this:

REPLACE (StringColumn, 'SearchForThis', 'ReplaceWithThis')

e.g.

REPLACE (StringColumn, '  ', ' ')