Home Forums SQL Server 2005 T-SQL (SS2K5) how to verify blank spaces using substr function in SQLSERVER 2008 RE: how to verify blank spaces using substr function in SQLSERVER 2008

  • May be this will help

    ________________________________________________________

    declare @word varchar(125) = 'The Quick Brown Fox Jumps over a lazy Dog'

    declare @swrd varchar(100)

    declare @l int

    while len(@word) > 0

    Begin

    set @l = CHARINDEX(' ',@word)

    if @l = 0 -- No space found

    set @swrd = @word

    else

    set @swrd = SUBSTRING( @word, 1, @l )

    Print 'Word inserted will be ' + @swrd

    set @word = SUBSTRING( @word, len(@swrd)+2, LEN(@word)-len(@swrd)+1 )

    end