I have to create a function in mysql database, that checks if given datetime variable is between two other (one of them may be null so checks if it's between first datetime and current timestamp), then if it's between them function returns 0, if not between returns double variable given as parameter. My code looks like this:
delimiter //
create function oplata (oplata double(19,2), dataaktywnosci datetime, dataaktywacji datetime, datadezaktywacji datetime)
returns double(19,2)
begin
if datadezaktywacji = NULL then
if dataaktywnosci between dataaktywacji and CURRENT_TIMESTAMP then return 0;
end if;
end if;
else
if dataaktywnosci between dataaktywacji and datadezaktywacji then return 0;
end if;
else
if dataaktywnosci not between dataaktywacji and datadezaktywacji then return oplata;
end if;
end//
delimiter;
And returns error
Error Code: 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 'else if dataaktywnosci between dataaktywacji and datadezaktywacji then return 0;' at line 8
I double-checked everything at dev.mysql.com, googled the problem, checked my code if I made a mistake and I just can't notice what's wrong. Anyone had similar problem or just know how to make it work?
Aucun commentaire:
Enregistrer un commentaire