EnexoOnoma
EnexoOnoma

Reputation: 8836

Help on removing the aliases from a MySQL trigger

my question is too easy (I guess), below is an example of trigger that I am trying to remove the aliases. I don't know what I am doing wrong I just can't get it right.

DELIMITER @
CREATE TRIGGER StartOfShift BEFORE INSERT ON shift
FOR EACH ROW
BEGIN
IF(NEW.CashierCode NOT IN ( SELECT w.EmployeeID FROM WorksOn as w
JOIN shop AS s ON w.ShopID = s.ShopID
JOIN CashMachineCode AS c ON s.ShopID = c.ShopID
WHERE c.CashMachineCode = NEW.CashMachineCode ))
THEN SET NEW.CashierCode = NULL;
END IF;
END;

Upvotes: 0

Views: 89

Answers (1)

cEz
cEz

Reputation: 5062

The following should be what you are looking for:

DELIMITER @
CREATE TRIGGER StartOfShift BEFORE INSERT ON shift
FOR EACH ROW
BEGIN
    IF(NEW.CashierCode NOT IN ( 
        SELECT WorksOn.EmployeeID FROM WorksOn
            JOIN shop ON WorksOn.ShopID = shop.ShopID
            JOIN CashMachineCode ON shop.ShopID = CashMachineCode.ShopID
            WHERE CashMachineCode.CashMachineCode = NEW.CashMachineCode )
    ) THEN 
        SET NEW.CashierCode = NULL;
    END IF;
END@
DELIMITER ;

Upvotes: 1

Related Questions