Reputation: 193
I cannot seem to get a DATE declared as a variable in phpMyAdmin. I always seem to get the following error:
1064 - 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 '@check_in date = '2019-12-11', @check_out = '2019-12-17';
The syntax of my query has gone from :
Declare @checkIn date = '2019-12-11'
, @checkOut date = '2019-12-17'
select *
from CURRENT_BOOKINGS
where booked_from not between @checkIn and @checkOut
and booked_to not between @checkIn and @checkOut'
To ...
DELIMITER $$
CREATE PROCEDURE roomAvailable()
BEGIN
DECLARE @check_in DATE;
SET @check_in = '2019-12-11';
DECLARE @check_out DATE
SET @check_in = '2019-12-17'
SELECT * FROM CURRENT_BOOKINGS
WHERE booked_from NOT BETWEEN @check_in AND @check_out
AND booked_to NOT BETWEEN @check_in AND @check_out
END $$
as I have gone through multiple iterations trying to find the cause. Any help appreciated as I am stumped
Upvotes: 0
Views: 181
Reputation: 204854
Don't use @
and all declare
s have to be at the beginning
DELIMITER $$
CREATE PROCEDURE roomAvailable()
BEGIN
DECLARE check_in DATE;
DECLARE check_out DATE;
SET check_in = '2019-12-11';
SET check_out = '2019-12-17';
SELECT * FROM CURRENT_BOOKINGS
WHERE booked_from NOT BETWEEN check_in AND check_out
AND booked_to NOT BETWEEN check_in AND check_out;
END $$
Upvotes: 1