Home Forums SQL Server 2005 T-SQL (SS2K5) ANYTHING THAT CAN HELP TRIM THE DATA FOR A GIVEN STRING... RE: ANYTHING THAT CAN HELP TRIM THE DATA FOR A GIVEN STRING...

  • 'A COSMETOLOGIST uses knowledge to do things to a client`s hair. A HAIRAPIST uses knowledge to give a customer guidance so she can do her own "hair improvement". '

    well, u don't see it becoz i posted as plain text. This might help here.

    I do have a function, but I just don't want to use functions if there is alternatives.

    here is code for function

    CREATE function [dbo].[cleanString2](@string varchar(MAX))

    returns varchar(MAX)

    AS

    Begin

    if charindex(' ', @string) = 0 return @string

    set @string = replace(@string, ' ',' ')

    while charindex(' ', @string) > 0

    select @string = dbo.cleanString2(@string) --recursive call

    return rtrim(ltrim(@string))

    End

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

    CREATE function [dbo].[fn_RemoveWhtSpaces](@string varchar(MAX))

    returns varchar(MAX)

    AS

    Begin

    if charindex(' ', @string) = 0 return @string

    set @string = replace(@string, ' ',' ')

    while charindex(' ', @string) > 0

    select @string = dbo.cleanString2(@string) --recursive call

    return rtrim(ltrim(@string))

    End