Stored procedure Cursor loop not iterating

I have a cursor loop within a stored procedure and it does not appear to by iterating.n The original querry returns 4 records but my insert is only inserting onece. So it looks like @BOLFBID is not iterating correctly. Here is my code.

            DECLARE @BOLFBID int      
            DECLARE BOLCursor CURSOR FOR       
                  select distinct FBID from tblbillproducts where bol=@bol

            OPEN BOLCursor
            WHILE @@FETCH_STATUS = 0
                  ---First we will delete all records in the temp table that are associated with this FBID #
                  delete from tbltempbol where FBID=@BOLFBID
                  -- insert into a flat table because there is no way to relate the imagesid up with the correct bol number
                  Insert into tbltempBOL (FBID,POD,UNLOADDATE,CUSTOMERID,BOL,CustomerName,IMageID,ImageTypeID,TypeDescription)
                  Select distinct B.FBID,B.POD,B.UnLoadDate,B.CustomerID,0 As BOL,C.CustomerName,I.ImageID,IT.ImageTypeID,
                  FROM tblBill AS B  
                  inner join tblImages AS I on (B.POD = I.Index1 OR CAST(B.FBID AS NVARCHAR(255)) = I.Index1  AND I.ImageGroupID='FB')
                  inner join tblImageTypes AS IT on (I.ImageTypeID = IT.ImageTypeID)
                  inner join tblCustomers AS C  on(B.CustomerID = C.CustomerID  )
                  inner join tblBillProducts BP on(B.FBID=BP.FBID)
                  where  b.FBID=@BOLFBID


      CLOSE BOLCursor
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Nathan RileyFounderCommented:
This is the only part from the cursor that is affecting the insert, so it is only true one 1 row and now all 4 like before.
where  b.FBID=@BOLFBID

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
soccerman777Author Commented:
Actually I did not give you enough code to figure out what the problem was. I had declared @BOL as nvarchar  I did not declare nvarchar(20) like I should have. So when I inputed 90975 it was only seeing 9. But since I put you at disadvantage you get the soultion points.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2005

From novice to tech pro — start learning today.