Jeff, you've come up with a nice, simple method for doing this. It made me go back and look at how I had coded it in my application. My code seems to avoid RBAR, and also deals with other "space" characters (tabs and cr/lf) [something that could be easily added to your method, of course.] But my code is more convulted and probably less efficient due to the creation of a temp table to split the words into:
CREATE procedure [dbo].[removeExtraWhiteSpace]
@test varchar(max) output
SET NOCOUNT ON
set @test = replace(@test,char(9),' ')
set @test = replace(@test,char(10),' ')
set @test = replace(@test,char(13),' ')
set @test = replace(@test,'''', '''''')
CREATE TABLE #words(seq int identity, singlePhrase varchar(8000))
-- Split by words and load text into the table
SELECT @test = 'INSERT INTO #words(singlePhrase) SELECT A=''' +
REPLACE(@test, ' ', ''' UNION ALL SELECT ''') + ''''
set @test = '';
select @test = @test + singlePhrase + ' ' FROM #words where ltrim(singlePhrase) > '' order by seq;
drop table #words
I think I'll switch over to your method.