Home Forums SQL Server 7,2000 T-SQL Finding & removing a space from a string RE: Finding & removing a space from a string

  • quote:


    Works like a charm, thanks!


    Thanks! This is my first time making suggestions on this site. I always come here for questions instead 🙂 Here's a loop to remove multiple spaces...

    -------------------------------------------

    declare @strName varchar(100)

    select @strName = ' S t J a m e s '

    while charindex(' ',@strName) > 0

    begin

    select @strName = ltrim(@strName)

    select @strName = rtrim(@strName)

    select @strName = left(@strName,(charindex(' ',@strName)-1))+right(@strName,(len(@strName)-charindex(' ',@strName)))

    end

    select @strName

    -------------------------------------------

    Edited by - fubak on 08/20/2003 1:13:54 PM