Is there a more elegant way of doing this. I want to replace repeating blanks with single blanks….
declare @i int
set @i=0
while @i <= 20
begin
update myTable
set myTextColumn = replace(myTextColumn, ' ', ' ')
set @i=@i+1
end
(its sql server 2000 – but I would prefer generic SQL)
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