Hi All. I'm trying to create a trigger that runs before insert.
Here's my trigger as written.
DROP TRIGGER IF EXISTS onTransactionInsert;
DELIMITER |
CREATE TRIGGER onTransactionInsert BEFORE INSERT ON `transactions`
FOR EACH ROW
BEGIN
SET new.runningBalNormal = new.amount + SELECT sum(`amount`) FROM `transactions`
WHERE DATE_SUB( CURDATE( ) , INTERVAL 30 DAY ) <= `date` AND
`userID` = new.userID AND `acctID` = new.acctID;
END |
DELIMITER ;
Now what has me really confused is that the following line works fine just entered as SQL. So why is it throwing an error when I try to use it in the trigger?
SELECT sum( `amount` )
FROM `transactions`
WHERE DATE_SUB( CURDATE( ) , INTERVAL 30
DAY ) <= `date`
AND `userID` =4
AND `acctID` =1
TIA!
Here's my trigger as written.
DROP TRIGGER IF EXISTS onTransactionInsert;
DELIMITER |
CREATE TRIGGER onTransactionInsert BEFORE INSERT ON `transactions`
FOR EACH ROW
BEGIN
SET new.runningBalNormal = new.amount + SELECT sum(`amount`) FROM `transactions`
WHERE DATE_SUB( CURDATE( ) , INTERVAL 30 DAY ) <= `date` AND
`userID` = new.userID AND `acctID` = new.acctID;
END |
DELIMITER ;
Now what has me really confused is that the following line works fine just entered as SQL. So why is it throwing an error when I try to use it in the trigger?
SELECT sum( `amount` )
FROM `transactions`
WHERE DATE_SUB( CURDATE( ) , INTERVAL 30
DAY ) <= `date`
AND `userID` =4
AND `acctID` =1
TIA!