Results 1 to 3 of 3

Thread: SProc Error...Error near Else

  1. #1

    Thread Starter
    Frenzied Member StrangerInBeijing's Avatar
    Join Date
    Mar 2005
    Location
    Not in Beijing
    Posts
    1,666

    Resolved 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)
    Last edited by StrangerInBeijing; Sep 10th, 2006 at 08:55 PM.

  2. #2
    Frenzied Member axion_sa's Avatar
    Join Date
    Jan 2002
    Location
    Joburg, RSA
    Posts
    1,724

    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

  3. #3

    Thread Starter
    Frenzied Member StrangerInBeijing's Avatar
    Join Date
    Mar 2005
    Location
    Not in Beijing
    Posts
    1,666

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width