I have trouble with my computed column for calculate automatically age. I use latest version of Laragon, with HeidiSQL (11.2.06213).
See the request :
CREATE TABLE client(
id_client Int Auto_increment NOT NULL ,
client_date_naissance Date NOT NULL ,
age Int AS YEAR(NOW) - YEAR(client_date_naissance)
- (CASE WHEN MONTH(client_date_naissance) > MONTH(NOW)
OR (MONTH(@client_date_naissance) = MONTH(NOW)
AND DAY(client_date_naissance) > DAY(NOW)) THEN 1 ELSE END);
,CONSTRAINT client_PK PRIMARY KEY (id_client)
)ENGINE=InnoDB;
I tried with "currendate
" instead of "NOW
", same with supressed the "int" for age.
In SQL's doc, i found this "TIMESTAMPDIFF(YEAR,birth,CURDATE())
" but doesn't work.
I precise , the meaning of "client_date_naissance" (french) is equal to birthday.
The error, for all case is :
Erreur SQL (1064) : You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'YEAR(NOW) - YEAR(client_date_naissance) - (CASE WHEN MONTH(client_date_naissance'
Any ideas ? Thank for support.