abenitez77
IS-IT--Management
I am getting error msg's with my syntax. . Can you help me out ?Declare @StoreNum int Declare @StoreCnt int Declare @Recid intSet @Recid = Select MAX(RECNO) as recno from dbo.as_AllStores GODrop Table dbo.as_Redemption_Offers_DayGapGOSelect 'Redemption' As Redemption, ar3.*, 'Offers->' As Offers, ao.* Into dbo.as_Redemption_Offers_DayGapFROM 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 NULLGOSet @Recid = @Recid - 1GOWhile @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 - 1End Error Msg:Msg 156, Level 15, State 1, Line 5Incorrect syntax near the keyword 'Select'.Msg 137, Level 15, State 2, Line 6Must declare the scalar variable "@Recid".Msg 137, Level 15, State 2, Line 12Must declare the scalar variable "@Recid".Msg 137, Level 15, State 2, Line 18Must declare the scalar variable "@Recid".Msg 137, Level 15, State 2, Line 1Must declare the scalar variable "@Recid".Msg 137, Level 15, State 2, Line 1Must declare the scalar variable "@Recid".Msg 156, Level 15, State 1, Line 5Incorrect syntax near the keyword 'Select'.Msg 137, Level 15, State 2, Line 9Must declare the scalar variable "@Recid".Msg 137, Level 15, State 2, Line 15Must declare the scalar variable "@Recid".Msg 137, Level 15, State 2, Line 21Must declare the scalar variable "@Recid".Msg 137, Level 15, State 2, Line 27Must declare the scalar variable "@Recid".