SProc Error...Error near Else
Hi,
Can someone tell me what i wrong with this sproc? I get this error:
Code:
Server: Msg 156, Level 15, State 1, Procedure sp_CAPL_InsertUpdateCompany_Normal, Line 22
Incorrect syntax near the keyword 'ELSE'.
Server: Msg 156, Level 15, State 1, Procedure sp_CAPL_InsertUpdateCompany_Normal, Line 26
Incorrect syntax near the keyword 'ELSE'.
SPROC:
Code:
ALTER PROCEDURE sp_CAPL_InsertUpdateCompany_Normal
@coID INT,
@coTypeID INT,
@phone_code NVARCHAR(10),
@phone_number NVARCHAR(20),
@phone_ext NVARCHAR(10),
@fax_code NVARCHAR(10),
@fax_number NVARCHAR(20)
AS
DECLARE @conID INT
IF EXISTS (SELECT [ID] FROM tblCAPLCompanies_Normal WHERE [ID] = @coID)
UPDATE tblCAPLCompanies_Normal
SET coTypeID = @coTypeID
WHERE [ID] = @coID
SET @conID =( SELECT contactID FROM tblCAPLCompanies_Normal WHERE [ID] = @coID)
IF @conID = 0
INSERT INTO tblContacts(phone_code, phone_number, phone_ext, fax_code, fax_number)
VALUES (@phone_code, @phone_number, @phone_ext, @fax_code, @fax_number)
SET @conID = SCOPE_IDENTITY()
INSERT INTO tblCAPLCompanies_Normal(contactID)
VALUES (@conID)
ELSE
UPDATE tblContacts
SET phone_code = @phone_code, phone_number = @phone_number, phone_ext = @phone_ext, fax_code = @fax_code, fax_number = @fax_number
WHERE ID = @conID
ELSE
INSERT INTO tblContacts(phone_code, phone_number, phone_ext, fax_code, fax_number)
VALUES (@phone_code, @phone_number, @phone_ext, @fax_code, @fax_number)
SET @conID = SCOPE_IDENTITY()
INSERT INTO tblCAPLCompanies_Normal(contactID)
VALUES (@conID)
Re: SProc Error...Error near Else
When you use multiple statements in a if/else block, need to have BEGIN and END...
IF EXISTS(...)
BEGIN
-- Statements...
IF @conID = 0
BEGIN
-- Statements
END
ELSE
BEGIN
-- Statements
END
END
ELSE
BEGIN
-- Statements
END
Re: SProc Error...Error near Else
dankie my maat!
het die kangaroo's lekker op hulle donner gegee daar onder huh?
cant wait to get to work now...boss is australian! haha