×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Insert with Loop

Insert with Loop

Insert with Loop

(OP)
I am getting error msg's with my syntax.  .  Can you help me out ?

Declare @StoreNum int
Declare @StoreCnt int
Declare @Recid int

Set @Recid = Select MAX(RECNO) as recno from dbo.as_AllStores
GO
Drop Table dbo.as_Redemption_Offers_DayGap
GO
Select 'Redemption' As Redemption, ar3.*, 'Offers->' As Offers, ao.*
Into dbo.as_Redemption_Offers_DayGap
FROM dbo.as_offer_dates as ao  
    Inner Join (Select *
                From dbo.as_all_division_coupons
                Where @Recid = RECNO ) AS ar1
    ON ao.[date] - 1 = ar1.SCAN_DATE_CONVERT AND
        ao.DivNum = ar1.Kma_div_nbr AND
        ao.cpnnum = ar1.coupon_nbr
    Inner Join (Select *
                From dbo.as_all_division_coupons
                Where @Recid = RECNO ) AS ar2
    ON ao.[date] + 1 = ar2.SCAN_DATE_CONVERT AND
        ao.DivNum = ar2.Kma_div_nbr AND
        ao.cpnnum = ar2.coupon_nbr
    Left Join (Select *
                From dbo.as_all_division_coupons
                Where @Recid = RECNO ) As ar3
    ON ao.[date] = ar3.SCAN_DATE_CONVERT AND
        ao.DivNum = ar3.Kma_div_nbr AND
        ao.cpnnum = ar3.coupon_nbr
WHERE ar3.STORE IS NULL
GO
Set @Recid = @Recid - 1
GO
While @Recid > 0   
begin

Insert Into dbo.as_Redemption_Offers_DayGap     
    (Select 'Redemption' As Redemption, ar3.*, 'Offers->' As Offers, ao.*
    FROM dbo.as_offer_dates as ao  
        Inner Join (Select *
                    From dbo.as_all_division_coupons
                    Where @Recid = RECNO ) AS ar1
        ON ao.[date] - 1 = ar1.SCAN_DATE_CONVERT AND
            ao.DivNum = ar1.Kma_div_nbr AND
            ao.cpnnum = ar1.coupon_nbr
        Inner Join (Select *
                    From dbo.as_all_division_coupons
                    Where @Recid = RECNO ) AS ar2
        ON ao.[date] + 1 = ar2.SCAN_DATE_CONVERT AND
            ao.DivNum = ar2.Kma_div_nbr AND
            ao.cpnnum = ar2.coupon_nbr
        Left Join (Select *
                    From dbo.as_all_division_coupons
                    Where @Recid = RECNO ) As ar3
        ON ao.[date] = ar3.SCAN_DATE_CONVERT AND
            ao.DivNum = ar3.Kma_div_nbr AND
            ao.cpnnum = ar3.coupon_nbr
    WHERE ar3.STORE IS NULL)

    Set @Recid = @Recid - 1

End


Error Msg:
Msg 156, Level 15, State 1, Line 5
Incorrect syntax near the keyword 'Select'.
Msg 137, Level 15, State 2, Line 6
Must declare the scalar variable "@Recid".
Msg 137, Level 15, State 2, Line 12
Must declare the scalar variable "@Recid".
Msg 137, Level 15, State 2, Line 18
Must declare the scalar variable "@Recid".
Msg 137, Level 15, State 2, Line 1
Must declare the scalar variable "@Recid".
Msg 137, Level 15, State 2, Line 1
Must declare the scalar variable "@Recid".
Msg 156, Level 15, State 1, Line 5
Incorrect syntax near the keyword 'Select'.
Msg 137, Level 15, State 2, Line 9
Must declare the scalar variable "@Recid".
Msg 137, Level 15, State 2, Line 15
Must declare the scalar variable "@Recid".
Msg 137, Level 15, State 2, Line 21
Must declare the scalar variable "@Recid".
Msg 137, Level 15, State 2, Line 27
Must declare the scalar variable "@Recid".
 

RE: Insert with Loop

(OP)
Will do...thanks

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close