Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Please what's wrong with this statement

Author  Topic 

Tarek Z. Rabadi
Starting Member

2 Posts

Posted - 2014-01-21 : 09:14:07
declare @Getthedate date
set @Getthedate='01/01/2014'
case
when month(@Getthedate)=1 then
update gam_monthly_9999 GM
set Gm.jan_balance=GD.balance,GM.Jan_Currate=GD.currate,GM.Jan_Avg=GD.AGR_AMT
From Gam_9999 GD
where GD.forthedate=@Getthedate and GD.accno=GM.accno and GD.glno=GM.glno and GD.cur=GM.cur
when month(@Getthedate)=2 then
update gam_monthly_9999 GM
set Gm.Feb_balance=GD.balance,GM.Feb_Currate=GD.currate,GM.Feb_Avg=GD.AGR_AMT
From Gam_9999 GD
where GD.forthedate=@Getthedate and GD.accno=GM.accno and GD.glno=GM.glno and GD.cur=GM.cur
when month(@Getthedate)=3 then
update gam_monthly_9999 GM
set Gm.Mar_balance=GD.balance,GM.Mar_Currate=GD.currate,GM.Mar_Avg=GD.AGR_AMT
From Gam_9999 GD
where GD.forthedate=@Getthedate and GD.accno=GM.accno and GD.glno=GM.glno and GD.cur=GM.cur
when month(@Getthedate)=4 then
update gam_monthly_9999 GM
set Gm.Apr_balance=GD.balance,GM.Apr_Currate=GD.currate,GM.Apr_Avg=GD.AGR_AMT
From Gam_9999 GD
where GD.forthedate=@Getthedate and GD.accno=GM.accno and GD.glno=GM.glno and GD.cur=GM.cur
when month(@Getthedate)=5 then
update gam_monthly_9999 GM
set Gm.May_balance=GD.balance,GM.May_Currate=GD.currate,GM.May_Avg=GD.AGR_AMT
From Gam_9999 GD where GD.forthedate=@Getthedate and GD.accno=GM.accno and GD.glno=GM.glno and GD.cur=GM.cur
when month(@Getthedate)=6 then
update gam_monthly_9999 Gm
set Gm.Jun_balance=GD.balance,GM.Jun_Currate=GD.currate,GM.Jun_Avg=GD.AGR_AMT
From Gam_9999 GD
where GD.forthedate=@Getthedate and GD.accno=GM.accno and GD.glno=GM.glno and GD.cur=GM.cur
when month(@Getthedate)=7 then
update gam_monthly_9999 Gm
set Gm.Jul_balance=GD.balance,GM.Jul_Currate=GD.currate,GM.Jul_Avg=GD.AGR_AMT
From Gam_9999 GD
where GD.forthedate=@Getthedate and GD.accno=GM.accno and GD.glno=GM.glno and GD.cur=GM.cur
when month(@Getthedate)=8 then
update gam_monthly_9999 Gm
set Gm.Aug_balance=GD.balance,GM.Aug_Currate=GD.currate,GM.Aug_Avg=GD.AGR_AMT
From Gam_9999 GD
where GD.forthedate=@Getthedate and GD.accno=GM.accno and GD.glno=GM.glno and GD.cur=GM.cur
when month(@Getthedate)=9 then
update gam_monthly_9999 GM
set Gm.Sep_balance=GD.balance,GM.Sep_Currate=GD.currate,GM.Sep_Avg=GD.AGR_AMT
From Gam_9999 GD
where GD.forthedate=@Getthedate and GD.accno=GM.accno and GD.glno=GM.glno and GD.cur=GM.cur
when month(@Getthedate)=10 then
update gam_monthly_9999 Gm
set Gm.Oct_balance=GD.balance,GM.Oct_Currate=GD.currate,GM.Oct_Avg=GD.AGR_AMT
From Gam_9999 GD
where GD.forthedate=@Getthedate and GD.accno=GM.accno and GD.glno=GM.glno and GD.cur=GM.cur
when month(@Getthedate)=11 then
update gam_monthly_9999 Gm
set Gm.Nov_balance=GD.balance,GM.Nov_Currate=GD.currate,GM.Nov_Avg=GD.AGR_AMT
From Gam_9999 GD
where GD.forthedate=@Getthedate and GD.accno=GM.accno and GD.glno=GM.glno and GD.cur=GM.cur
when month(@Getthedate)=12 then
update gam_monthly_9999 GM
set Gm.Dec_balance=GD.balance,GM.Dec_Currate=GD.currate,GM.Dec_Avg=GD.AGR_AMT
From Gam_9999 GD
where GD.forthedate=@Getthedate and GD.accno=GM.accno and GD.glno=GM.glno and GD.cur=GM.cur
end

T.Z.R

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2014-01-21 : 09:26:50
case is not a control flow statement. you need to use if instead

declare @Getthedate date
set @Getthedate='01/01/2014'

if month(@Getthedate)=1
update gam_monthly_9999 GM
set Gm.jan_balance=GD.balance,GM.Jan_Currate=GD.currate,GM.Jan_Avg=GD.AGR_AMT
From Gam_9999 GD
where GD.forthedate=@Getthedate and GD.accno=GM.accno and GD.glno=GM.glno and GD.cur=GM.cur

if month(@Getthedate)=2
update gam_monthly_9999 GM
set Gm.Feb_balance=GD.balance,GM.Feb_Currate=GD.currate,GM.Feb_Avg=GD.AGR_AMT
From Gam_9999 GD
...


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

Tarek Z. Rabadi
Starting Member

2 Posts

Posted - 2014-01-22 : 01:16:40
thanks , i used the if as u suggested thanks again

T.Z.R
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2014-01-22 : 06:27:49
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -