Sign up ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

I am new to mysql, I have been using SQL in the past. I am trying to insert rows into a table via creating a loop. But struggling with it. Any help?

DECLARE @minid  INT = (SELECT MIN(Product_ID) FROM    
    Product_Report_Offer_Interaction_Jan_2012 pn)
DECLARE @maxid  INT = (SELECT max(Product_ID) FROM 
    Product_Report_Offer_Interaction_Jan_2012 pn)

DECLARE @topid INT= @minid + 50000

WHILE ( @minid < @maxid ) 
        insert into  Product_Report_Offer_Jan_2012 (Month, Product_ID, Offerview, 
        EnlargeImage, DynamicPopUp, ShareonFacebook, BuyNowPress, Sendtofriend,
        Printed, StoreLocated, uLike, iPhoneOfferDetails, iPhoneStoreLocated, 
        WishlistAd, Tweet, Catalogue1pageview, Catalogue2pageview, SearchListing,
        Featured, RelatedAdImpression, Wishlist)
        select pn.Month, pn.Product_ID, pn.Offerview, pn.EnlargeImage, 
        pn.DynamicPopUp, pn.ShareonFacebook, pn.BuyNowPress, pn.Sendtofriend,       
        pn.Printed, pn.StoreLocated, pn.uLike, pn.iPhoneOfferDetails, 
        pn.iPhoneStoreLocated, pn.WishlistAd, pn.Tweet, pm.Catalogue1pageview,
        pm.Catalogue2pageview, pm.SearchListing, pm.Featured,       
        -- select count(*)
        -- select *  
        from Product_Report_Offer_Interaction_Jan_2012 pn
            left join Product_Report_Offer_Impression_Jan_2012 pm on pn.product_ID = pm.product_ID 
            where pn.product_id != '0'
                and pn.Product_ID BETWEEN @minid AND @topid

        SET @minid = @minid + 50000 + 1
        SET @topid = @topid + 50000 + 1


Thanks jakub

share|improve this question

1 Answer 1

User-defined session-scope variables, beginning with @ are not declared and are loosely and implicitly typed. Change DECLARE to SET and drop the INT after the variable name if these are the variables you intend to use.

Program variables are declared and typed, and do not start with @.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.