variable is not being passed in nested while....

  • Hey guys i have a quick newb question...

    I'm trying write a little something that will loop through our products and break up the description line by line

    For example...

    "Green Jelly Beans" broken up to:

    Green

    Jelly

    Beans

    This works for the first row... but on the next loop, @productDecription doesn't passed into the Phrase breaking while ....

    Any advice or is it something i'm misssing>?? :hehe:?

    Thanks in advance.

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

    --

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

    declare @TotalNumberOfItems int

    declare @helperNumber int

    declare @incrementer int

    declare @RowCounter int

    declare @productDescription varchar(100)

    declare @broken varchar(100)

    select @TotalNumberOfItems = 50 --(select count(*) from #TempTable)

    select @helperNumber = 50

    select @incrementer = 1

    select @RowCounter = 1

    WHILE (@RowCounter <= @TotalNumberOfItems)

    BEGIN

    select @productDescription = (select pText from #TempTable where RowNum = @RowCounter)

    print @RowCounter

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

    WHILE (@incrementer <= @helperNumber)

    BEGIN

    IF ( @incrementer <= LEN(@productDescription) AND SUBSTRING(' ' + @productDescription, @incrementer, 1) = ' ' )

    BEGIN

    select @broken = (SELECT SUBSTRING(@productDescription+' ', @incrementer, CHARINDEX(' ', @productDescription+' ', @incrementer) - @incrementer) )

    print @broken

    END

    select @incrementer = @incrementer + 1

    END

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

    select @RowCounter = @RowCounter + 1

    END

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

  • ah....

    i forgot to reset incrementer for the next round of the inner loop

    select @incrementer = 1

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply