Created
May 30, 2015 11:10
-
-
Save Metrakit/de937634346771eebe76 to your computer and use it in GitHub Desktop.
#1336 - Dynamic SQL is not allowed in stored function or trigger
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DELIMITER | | |
DROP TRIGGER IF EXISTS `vote_update` | | |
CREATE TRIGGER `vote_update` | |
AFTER INSERT ON `votes` | |
FOR EACH ROW | |
BEGIN | |
SET @row_day = CONCAT(DAYNAME(NOW()), '_votes'); | |
SET @sql_weekly := 'INSERT INTO `weekly_stats` (`server_id`, `year`, `number`,' + @row_day + | |
'VALUES(NEW.server_id,' + YEAR(NOW()) + ',' + WEEK(NOW()) + ', 1) | |
ON DUPLICATE KEY UPDATE' + @row_day + '=' + @row_day + '+1'; | |
PREPARE weekly_stats FROM @sql_weekly; | |
EXECUTE weekly_stats; | |
END; | |
| |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment