Stored Procedure Syntax Problem
I am a beginning user of sql server and I keep getting a syntax error at my else statements. The following is the code I have been using. Please help me out
Thank You
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE PROC dbo. SP_AccessorialCharges AS
--Created by Max Gay
--November 4, 2004
--Declare variables
DECLARE @Notification BIT, @InsideDel BIT, @LiftGate BIT, @ResidentialDel
BIT, @HazMat BIT, @DropCharge BIT, @CompanyNumber BIGINT, @CarrierNumber
BIGINT, @Weight BIGINT, @AccChrg MONEY, @AccChrgTot MONEY, @Exception8
VARCHAR, @Exception5 VARCHAR, @Exception6 VARCHAR, @displayError INT
--Actual work
SELECT * FROM dbo.[Carrier Profiles] WHERE ([Carrier Number]=82) AND
([Company Number]=7)
--Display error codes and set exceptions
BEGIN
IF @Notification= 1
IF [Notification] = 'No Service'
IF @Exception8 = 'Update'
SET @displayError = '1'
SET @AccChrg = CAST (@Exception5 AS MONEY)
END
ELSE
BEGIN
SET @AccChrg = @AccChrg + [Notification]
END
--Inside Delivery
BEGIN
IF @InsideDel= 1
IF [Inside delivery CWT] = 'No Service'
SET @displayError = 2
END
ELSE
BEGIN
SET @AccChrg = @AccChrg + [Inside delivery CWT] * (@Weight/100)
END
BEGIN
IF @AccChrg < [Inside delivery MIN]
SET @AccChrg = [Inside delivery MIN]
IF @AccChrg < [Lift Gate MIN]
SET @AccChrg = [Lift Gate MIN]
IF @AccChrg < [Residential del MIN]
SET @AccChrg = [Residential del MIN]
END
ELSE
BEGIN
IF @AccChrg > [Inside delivery MAX]
SET @AccChrg = [Inside delivery MAX]
IF @AccChrg > [Lift Gate MAX]
SET @AccChrg = [Lift Gate MAX]
IF @AccChrg > [Residential del MAX]
SET @AccChrg = [Residential del MAX]
END
--Lift Gate
BEGIN
IF @LiftGate= 1
IF [Lift Gate CWT] = 'No Service'
SET @displayError = 3
END
ELSE
BEGIN
SET @AccChrg = @AccChrg + [Lift Gate CWT] * (@Weight/100)
END
--Residential Delivery
BEGIN
IF @ResidentialDel = 1
IF [Residential del CWT] = 'No Service'
SET @displayError = 4
END
ELSE
BEGIN
SET @AccChrg = @AccChrg + ([Residential del CWT]) * (@Weight/100)
END
--Haz Mat
BEGIN
IF @HazMat = 1
IF [Haz Mat] = 'No Service'
IF @Exception8 = 'Update'
SET @displayError = 5
SET @AccChrg =CAST (@Exception6 AS MONEY)
END
--Drop Charge
BEGIN
IF @DropCharge = 1
IF [Drop Charge] = 'No Service'
SET @displayError = 6
END
--Total accessorial charges
BEGIN
SET @AccChrgTot=@AccChrg
END
RETURN
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
Max
|