I've tried this 50 different ways and am not getting anywhere... I tried not using Temp table and it WORKS. I'm not sure but I believe my users won't be able to execute delete table with out me changing permissions to DB owner? I'd rather resolve this temp table issue. (Insert into didn't work either)
Here's my code
CREATE TABLE #RebRawdata2 (
[RebateAcct] [nvarchar] (4) ,
[BalFwd] [decimal](16, 2)
)
-- Different Quarter dif starting QT fiscal balance figures
if Month(Getdate()) in (1, 2, 3)
BEGIN
SET @monthBal1 = ' GL.beg_bal_12 * -1 '
END
ELSE IF Month(Getdate()) in (4, 5, 6)
BEGIN
SET @monthBal2 = ' GL.beg_bal_3 * -1 '
END
ELSE IF Month(Getdate())in (7, 8, 9)
BEGIN
SET @monthBal3 = ' GL.beg_bal_6 * -1 '
END
ELSE IF Month(Getdate())in (10, 11, 12)
BEGIN
SET @monthBal4 = ' GL.beg_bal_9 * -1 '
End
-- 3 balances should be empty so I'll only pick up the one that has data
SET @monthBal = Rtrim(Ltrim(@monthBal1)) + Rtrim(Ltrim(@monthBal2))+ Rtrim(Ltrim(@monthBal3)) + Rtrim(Ltrim(@monthBal4))
select @strSQL = ' Insert Into #RebRawdata2 select RD.RebateAcct , ' + ltrim(rtrim(@monthBal)) + ' From GLBALFIL_SQL AS GL Inner Join #RebRawdata AS RD ON RD.RebateAcct = Left(GL.Mn_No, 4) Group By RebateAcct Order By RebateAcct'
execute(@strSQL)
While @i <= @RebCount
Begin
-- I'm getting Invalid column name 'RebateAcct'here
Set @RebAcct = (Select Top 1 RebateAcct From #RebRawdata2 Order By RebateAcct)
-- I'm getting Invalid column name 'BalFwd'.here also
Set @RebBalFwd = (Select Top 1 BalFwd From #RebRawdata2 Order By RebateAcct)
Can anyone tell me what I'm missing here?
Thank You
CJ
Here's my code
CREATE TABLE #RebRawdata2 (
[RebateAcct] [nvarchar] (4) ,
[BalFwd] [decimal](16, 2)
)
-- Different Quarter dif starting QT fiscal balance figures
if Month(Getdate()) in (1, 2, 3)
BEGIN
SET @monthBal1 = ' GL.beg_bal_12 * -1 '
END
ELSE IF Month(Getdate()) in (4, 5, 6)
BEGIN
SET @monthBal2 = ' GL.beg_bal_3 * -1 '
END
ELSE IF Month(Getdate())in (7, 8, 9)
BEGIN
SET @monthBal3 = ' GL.beg_bal_6 * -1 '
END
ELSE IF Month(Getdate())in (10, 11, 12)
BEGIN
SET @monthBal4 = ' GL.beg_bal_9 * -1 '
End
-- 3 balances should be empty so I'll only pick up the one that has data
SET @monthBal = Rtrim(Ltrim(@monthBal1)) + Rtrim(Ltrim(@monthBal2))+ Rtrim(Ltrim(@monthBal3)) + Rtrim(Ltrim(@monthBal4))
select @strSQL = ' Insert Into #RebRawdata2 select RD.RebateAcct , ' + ltrim(rtrim(@monthBal)) + ' From GLBALFIL_SQL AS GL Inner Join #RebRawdata AS RD ON RD.RebateAcct = Left(GL.Mn_No, 4) Group By RebateAcct Order By RebateAcct'
execute(@strSQL)
While @i <= @RebCount
Begin
-- I'm getting Invalid column name 'RebateAcct'here
Set @RebAcct = (Select Top 1 RebateAcct From #RebRawdata2 Order By RebateAcct)
-- I'm getting Invalid column name 'BalFwd'.here also
Set @RebBalFwd = (Select Top 1 BalFwd From #RebRawdata2 Order By RebateAcct)
Can anyone tell me what I'm missing here?
Thank You
CJ