I am trying to create a stored procedure that would perform the select shown as the line before the end. It would take the earliest StartDate and the latest EndDate from my usertable and select all days between from those dates from my reference calendar table. Unfortunately whatever syntax I will try to use I will always get an error message on assigning the values from usertable selects to start/endday variables. I have not found many resources specifying the correct syntax from examples I have seen I tried the following.
DELIMITER $$
CREATE PROCEDURE seldays()
BEGIN
DECLARE startday DATE;
SET startday = (SELECT MIN(StartDate) from user1table1);
DECLARE endday DATE;
SET endday = (SELECT MAX(EndDate) from user1table1);
SELECT calendar_date FROM calendar WHERE calendar_date >= startday AND calendar_date< endday;
END $$
DELIMITER ;
I also tried to assign values thusly
SELECT MIN(StartDate) from user1table1 INTO endday;
To no avail. I might be able to make the procedure work without storing these variables - but it is something that I will sooner or later need to use anyway. So how does one fill local variables with query results in Mysql correctly?
SELECT calendar_date FROM calendar c, (SELECT MIN(StartDate) mindate, MAX(StartDate) maxdate from user1table1) u where c.calendar_date >= u.mindate and c.calendar_date <= u.maxdate)? Why a procedure instead of a simple select?