Try to search your question here, if you can't find : Ask Any Question Now ?

Cannot set variable to CURRENT_DATE() in MySQL trigger

HomeCategory: stackoverflowCannot set variable to CURRENT_DATE() in MySQL trigger
craig asked 6 days ago

I am writing a trigger to insert tuples into a relationship table. In the process, I amm trying to insert the current date into one column, using the native CURRENT_DATE() function. I have tried multiple calls to CURRENT_DATE(), but there is a persistent problem getting the date into my today variable.
Here is my code:

DELIMITER //
CREATE TRIGGER AjouterChose
AFTER INSERT ON UneTable
FOR EACH ROW
BEGIN
DECLARE aujourdHui DATE;
SET @aujourdHui := (SELECT CURRENT_DATE());
INSERT INTO AutreTable ER (IdProfil,Chose2,DateDebut)
VALUES (NEW.Responsable, NEW.IdChose2, @aujourdHui);
END;//
DELIMITER ;

The MySQL error message is:

ERROR 1064(42000): You have an error in your SQL syntax; check the manual ...
for the syntax to use near ';

I’ve tried:

@aujourdHui
aujourdHui
(SELECT @aujourdHui)
(SELECT aujourdHui)
CURRENT_DATE()
(SELECT CURRENT_DATE())

None of these worked. Not sure what else is there to try.

Any help would be appreciated.

1 Answers
Best Answer
Matthias answered 6 days ago
Your Answer

1 + 13 =

Popular Tags

WP Facebook Auto Publish Powered By : XYZScripts.com