multiple update in IF statement within stored procedure

i have this stored proc and its not letting me have 2 update statements under IF and ELSE. ITs givng me an error near ELSE. and how can i fix it?
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[sp_UpdateTotals2]
AS
BEGIN
 
SET NOCOUNT ON;
 
Declare @isWeekday  tinyint
Declare @isHoliday  tinyint
 
 
--Find out if today is weekend or holiday (True =1, False =0)
set @isWeekday =(select isWeekday  from Corp_calendar T where dt = CONVERT(VARCHAR(10),GETDATE(),101))  
set @isHoliday =  (select isHoliday  from Corp_calendar T where dt = CONVERT(VARCHAR(10),GETDATE(),101)) 
 
 
 --If its weekday, then do the following
IF @isWeekday=1 or @isHoliday =0 
 
 	UPDATE TB_Cummulative 
	SET TB_Cummulative.Cummulative_actual = D.ActualTotal, TB_Cummulative.Cummulative_target = D.TargetTotal
	FROM Auto_Daily_Total D 
	WHERE TB_Cummulative.Run_Date = convert(varchar(10),getdate(),101)  and TB_Cummulative.Board_ID = D.Board_ID
 
   UPDATE TB_Cummulative 
	SET TotalActual = D.TotalActual, TotalTarget = D.TotalTarget 
	FROM TB_Cummulative T 
    INNER JOIN Auto_Monthly_Total D ON T.Board_ID = D.Board_ID
    WHERE T.Run_Date = convert(datetime,CONVERT(VARCHAR(10),GETDATE(),101) ,101) AND D.MONTH=MONTH(GETDATE()) AND D.YEAR = YEAR(GETDATE())
 
ELSE
 
	UPDATE TB_Cummulative 
	SET 
			TB_Cummulative.Cummulative_actual = D.ActualTotal, 
			TB_Cummulative.Cummulative_target = 0
			FROM Auto_Daily_Total D
	WHERE 
			TB_Cummulative.Run_Date = convert(varchar(10),getdate(),101)  and 
			TB_Cummulative.Board_ID = D.Board_ID
 
	 UPDATE TB_Cummulative 
        SET 
                TotalActual = D.TotalActual, 
                TotalTarget = D.TotalTarget - T.Cummulative_Target
                FROM TB_Cummulative T 
                INNER JOIN Auto_Monthly_Total D ON T.Board_ID = D.Board_ID
        WHERE 
                T.Run_Date = convert(datetime,CONVERT(VARCHAR(10),GETDATE(),101) ,101)
				AND D.MONTH=MONTH(GETDATE()) 
                AND D.YEAR = YEAR(GETDATE())
	 
END

Open in new window

sassy168Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jorge SanchezSoftware EngineerCommented:
Between IF and ELSE insert:
BEGIN
.....
END
You have to use this keywords when you use multiple statements
0
Jorge SanchezSoftware EngineerCommented:
You have to do the same between ELSE and END
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[sp_UpdateTotals2]
AS
BEGIN
 
SET NOCOUNT ON;
 
Declare @isWeekday  tinyint
Declare @isHoliday  tinyint
 
 
--Find out if today is weekend or holiday (True =1, False =0)
set @isWeekday =(select isWeekday  from Corp_calendar T where dt = CONVERT(VARCHAR(10),GETDATE(),101))  
set @isHoliday =  (select isHoliday  from Corp_calendar T where dt = CONVERT(VARCHAR(10),GETDATE(),101)) 
 
 
 --If its weekday, then do the following
IF @isWeekday=1 or @isHoliday =0 
 BEGIN
        UPDATE TB_Cummulative 
        SET TB_Cummulative.Cummulative_actual = D.ActualTotal, TB_Cummulative.Cummulative_target = D.TargetTotal
        FROM Auto_Daily_Total D 
        WHERE TB_Cummulative.Run_Date = convert(varchar(10),getdate(),101)  and TB_Cummulative.Board_ID = D.Board_ID
 
   UPDATE TB_Cummulative 
        SET TotalActual = D.TotalActual, TotalTarget = D.TotalTarget 
        FROM TB_Cummulative T 
    INNER JOIN Auto_Monthly_Total D ON T.Board_ID = D.Board_ID
    WHERE T.Run_Date = convert(datetime,CONVERT(VARCHAR(10),GETDATE(),101) ,101) AND D.MONTH=MONTH(GETDATE()) AND D.YEAR = YEAR(GETDATE())
 END
ELSE
 BEGIN
        UPDATE TB_Cummulative 
        SET 
                        TB_Cummulative.Cummulative_actual = D.ActualTotal, 
                        TB_Cummulative.Cummulative_target = 0
                        FROM Auto_Daily_Total D
        WHERE 
                        TB_Cummulative.Run_Date = convert(varchar(10),getdate(),101)  and 
                        TB_Cummulative.Board_ID = D.Board_ID
 
         UPDATE TB_Cummulative 
        SET 
                TotalActual = D.TotalActual, 
                TotalTarget = D.TotalTarget - T.Cummulative_Target
                FROM TB_Cummulative T 
                INNER JOIN Auto_Monthly_Total D ON T.Board_ID = D.Board_ID
        WHERE 
                T.Run_Date = convert(datetime,CONVERT(VARCHAR(10),GETDATE(),101) ,101)
                                AND D.MONTH=MONTH(GETDATE()) 
                AND D.YEAR = YEAR(GETDATE())
  END       
END

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.