Есть база: MariaDB 5.5.27 (форк MySQL)
Есть процедура:
CREATE PROCEDURE koshka_get_day_records (IN user_id INT, IN country INT, IN udate DATETIME)
BEGIN
set @weekday = DATE_FORMAT(udate, '%w');
set @monthday = DATE_FORMAT(udate, '%d');
set @yearday = DATE_FORMAT(udate,'%m-%d');
set @datetime = udate;
set @mdl = DATE_FORMAT(udate,'%d');
IF (DATE_FORMAT(udate,'%d')=DATE_FROMAT(LAST_DAY(udate),'%d')) THEN set @mdl = '32';
END IF;
SELECT *
FROM koshka_calendar_records
WHERE user_id = @user_id
AND DATE_FORMAT(started_at,"%Y-%m-%d")<=DATE_FORMAT(@datetime,"%Y-%m-%d")
AND (DATE_FORMAT(finished_at,"%Y-%m-%d")>DATE_FORMAT(@datetime,"%Y-%m-%d") OR finished_at IS NULL)
AND (DATE_FORMAT(datetime,"%Y-%m-%d") = DATE_FORMAT(@datetime,"%Y-%m-%d")
OR weekday = @weekday
OR monthday = @monthday
OR DATE_FORMAT(yearday,"%m-%d") = DATE_FORMAT(@yearday,"%m-%d")
OR
(datetime IS NULL AND weekday IS NULL AND monthday IS NULL AND yearday IS NULL AND work_or_holyday IS NULL AND workday_counter IS NULL)
OR monthday = @mdl
OR
(work_or_holyday != (
select count(*) from koshka_work_calendar WHERE type IN ("weekend","holyday")
AND country = @country
AND DATE_FORMAT(date,"%Y-%m-%d")=DATE_FORMAT(@datetime,"%Y-%m-%d")
))
OR
workday_counter = (
select CAST(DATE_FORMAT(@datetime,"%d") as int)-count(*) from koshka_work_calendar
WHERE date <= @datetime
AND DATE_FORMAT(date,"%Y-%m")=DATE_FORMAT(@datetime,"%Y-%m")
AND country = @country
AND user_id=@user_id)
);
END
После того как делаем:
delimiter |
...код процедуры....
|
Возникает ошибка:
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '*) from koshka_work_calendar WHERE type IN ("weekend","holyday")
' at line 23
Не могу понять, в чем проблема. Как можно это решить?