I need to list all the dates between a given (prescription) start date and end date - (as a part of a much bigger query).
Table name: patientprescription
Start date field: prescriptionstartdate
End date field: prescriptionenddate
I'm trying to use session variables. But I find it difficult to set the initial value in the variable. First time execution doesn't result in any value but the subsequent execution gives me the correct result (because the first execution sets the variables).
To simplify my need, here is the gist of my query:
SELECT
@gg := DATE_ADD ( @gg, INTERVAL 1 DAY ) AS rxDate
FROM patientprescription AS rx
JOIN ( SELECT @gg := @hh FROM t1 ) AS v1 ON @hh := rx.prescriptionstartdate
WHERE
rx.id = 8
AND @gg <= rx.prescriptionenddate;
t1 is some table with a few records.
To reset the variables back after execution:
SELECT @gg := NULL, @hh := NULL;