Hey all,
I am new to doing if then else's in SQL and I am having a tough time. The Errors I am receiving are the following:
Msg 156, Level 15, State 1, Procedure Lane_Destination_R2, Line 72
Incorrect syntax near the keyword 'THEN'.
Msg 102, Level 15, State 1, Procedure Lane_Destination_R2, Line 77
Incorrect syntax near '='.
Msg 156, Level 15, State 1, Procedure Lane_Destination_R2, Line 82
Incorrect syntax near the keyword 'ELSE'.
Msg 156, Level 15, State 1, Procedure Lane_Destination_R2, Line 88
Incorrect syntax near the keyword 'END'.
I am guessing this is totally wrong, but it seems similar to the if then else clauses I find online. Any idea on how to clean this all up?
Thanks
-Bill
I am new to doing if then else's in SQL and I am having a tough time. The Errors I am receiving are the following:
Msg 156, Level 15, State 1, Procedure Lane_Destination_R2, Line 72
Incorrect syntax near the keyword 'THEN'.
Msg 102, Level 15, State 1, Procedure Lane_Destination_R2, Line 77
Incorrect syntax near '='.
Msg 156, Level 15, State 1, Procedure Lane_Destination_R2, Line 82
Incorrect syntax near the keyword 'ELSE'.
Msg 156, Level 15, State 1, Procedure Lane_Destination_R2, Line 88
Incorrect syntax near the keyword 'END'.
I am guessing this is totally wrong, but it seems similar to the if then else clauses I find online. Any idea on how to clean this all up?
Thanks
-Bill
Code:
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
ALTER PROCEDURE [dbo].[Lane_Destination_R2]
-- Add the parameters for the stored procedure here
(@UCC_bc nvarchar(50) = 99,
@DC_bc nvarchar(50) = 99,
@Zip_bc nvarchar(50) = 99,
@CustOut nvarchar(50) OUTPUT,
@Destination nvarchar(50) OUTPUT,
@Lane char(1) OUTPUT,
@ReasonCode nvarchar(50) OUTPUT,
@UniqueID nvarchar (50) OUTPUT)
AS
BEGIN
DECLARE @ContainerNum nvarchar(50)
DECLARE @DCID nvarchar(50)
DECLARE @Customer nvarchar(50)
DECLARE @ZipNum nvarchar(50)
DECLARE @Container nvarchar(50)
DECLARE @CustomerID nvarchar(50)
DECLARE @Retailer nvarchar(50)
DECLARE @RetailerID nvarchar(50)
DECLARE @UCCMode char(1)
DECLARE @DCIDMode char(1)
DECLARE @CustMode char(1)
DECLARE @ContMode char(1)
DECLARE @RetMode char(1)
DECLARE @Customer1 nvarchar(50)
DECLARE @Destination1 nvarchar(50)
DECLARE @Status char(1)
DECLARE @Reject char(1)
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
SELECT @Reject = LaneMap FROM dbo.LaneMappingTable1 WHERE Customer = 'Reject' AND Destination = 'Reject'
SELECT @Retailer = Retailer FROM dbo.Details WHERE CartonID = @UCC_BC
SELECT @Customer = Customer FROM dbo.Details WHERE CartonID = @UCC_BC
SELECT @ContainerNum = ContNum FROM dbo.Details WHERE CartonID = @UCC_BC
-- Insert statements for procedure here
SELECT * FROM dbo.SortRules WHERE (UCCMode = 'S' AND UCC = @UCC_bc)
IF DCID = @DCID AND DCIDMode = 'V' THEN
SELECT @Lane = LaneMap, @ReasonCode = '00' from dbo.LaneMappingTable1 where Customer = @CustOut and Destination = @Destination
SELECT @Lane = @Reject, @UniqueID = UniqueID from dbo.SortRules where UCC = @UCC_bc
ELSEIF @DCIDMode = 'V' THEN
SELECT @Lane = LaneMap, @ReasonCode = '02' from dbo.LaneMappingTable1 where Customer = @CustOut and Destination = @Destination
SELECT @Lane = @Reject, @UniqueID = UniqueID from dbo.SortRules where UCC = @UCC_bc
ELSE
SELECT @Lane = LaneMap, @ReasonCode = '01' from dbo.LaneMappingTable1 where Customer = @CustOut and Destination = @Destination
SELECT @Lane = @Reject, @UniqueID = UniqueID from dbo.SortRules where UCC = @UCC_bc
END IF
END