[dba-SQLServer] strip all leading / trailing spaces

Mark Rider ridermark at gmail.com
Thu Dec 7 07:48:21 CST 2006


This is from another thread on a similar subject - deleting spaces
from a field. Basically the SPROC loops through the field and replaces
it with fewer spaces than were there originally.

Since I am not much more advanced that pond scum, I am not positive
that it will work for you, but it may be a way to start!

begin
UPDATE Table SET FirstName = Replace(FirstName, '  ', ' ') where
charindex('  ', FirstName) > 0
while @@Rowcount > 0
begin
UPDATE Table SET FirstName = Replace(FirstName, '  ', ' ') where
charindex('  ', FirstName) > 0
end
end


-- 
Mark Rider
http://dfwmdug.org

Don't anthropomorphize computers.
They don't like it.



More information about the dba-SQLServer mailing list