views:

122

answers:

3

Hey guys, Im migrating from T-SQL to MySql syntax and don't know how to get over this syntax error given by Workbench 5.1.18:

-- --------------------------------------------------------------------------------
-- Routine DDL
-- --------------------------------------------------------------------------------
DELIMITER //

CREATE PROCEDURE `SysTicket`.`GetProductionLines` (aId INT, aActive INT, aResponsible VARCHAR(8000))
BEGIN
    IF(aId > 0) THEN SELECT * FROM ProductionLine WHERE Id = @Id;

    ELSE IF( aActive <> -1 AND aResponsible = '|$EMPTYARG$|') THEN SELECT * FROM ProductionLine;

    ELSE IF(aResponsible = '|$EMPTYARG&|') THEN SELECT * FROM ProductionLine WHERE Active = aActive;

    ELSE SELECT * FROM ProductionLine WHERE Active = aActive AND Responsible LIKE CONCAT('%', aResponsible, '%');

    END IF;    
END//

It says Syntax error near END (last line) ty in advance.

A: 

Remove the brackets from your IF statements for single comparisons or add commas instead of AND.

http://dev.mysql.com/doc/refman/5.1/en/control-flow-functions.html#function_if

Danten
A: 

-- -------------------------------------------------------------------------------- -- Routine DDL -- -------------------------------------------------------------------------------- DELIMITER //

CREATE PROCEDURE `SysTicket`.`GetProductionLines` (aId INT, aActive INT, aResponsible VARCHAR(8000))
BEGIN
    IF aId > 0 THEN SELECT * FROM ProductionLine WHERE Id = @Id;

    ELSE IF (aActive <> -1, aResponsible = '|$EMPTYARG$|') THEN SELECT * FROM ProductionLine;

    ELSE IF aResponsible = '|$EMPTYARG&|' THEN SELECT * FROM ProductionLine WHERE Active = aActive;

    ELSE SELECT * FROM ProductionLine WHERE Active = aActive AND Responsible LIKE CONCAT('%', aResponsible, '%');

    END IF;
END//

Still giving error...

Hugo S.
A: 

LOL. Figured it out... The correct syntax is:

ELSEIF

instead of

ELSE IF

LOL.

Hugo S.