Skip to content
Advertisement

SQL method to replace repeating blanks with single blanks

Is there a more elegant way of doing this. I want to replace repeating blanks with single blanks….

(its sql server 2000 – but I would prefer generic SQL)

Advertisement

Answer

Here is a simple set based way that will collapse multiple spaces into a single space by applying three replaces.

Your Update statement can now be set based:

Use an appropriate Where clause to limit the Update to only the rows that have you need to update or maybe have double spaces.

Example:

I have found an external write up on this method: REPLACE Multiple Spaces with One

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement