Quantcast
Channel: MySQL Forums - InnoDB
Viewing all articles
Browse latest Browse all 1957

Problem creating trigger (7 replies)

$
0
0
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!

Viewing all articles
Browse latest Browse all 1957

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>