anastasiasoul
asked on
SQL Query
Hi, Guys
I need to list all the patients admitted within the year to date. The query attached returns the empty set although there are definetely records to be returned. Where is my mistake?
Thanks
I need to list all the patients admitted within the year to date. The query attached returns the empty set although there are definetely records to be returned. Where is my mistake?
Thanks
select
admission.adno,
admission.pno,
patient.psurname,
SUBDATE(`currentdate`, INTERVAL 365 DAY)as to_date
from patient, admission, currentdate
where
patient.pno = admission.pno
and admission.indate between
currentdate and SUBDATE(`currentdate`, INTERVAL 365 DAY);
You don't need the back ticks, try CURRENT_DATE() or just CURRENT_DATE
ASKER
Thanks for your response.
Well, the point is that currentdate is a table in the DB to enter the date I require for testing purposes not the system date. And it works ok. I think there is something wrong with the expression SUBDATE(`currentdate`, INTERVAL 365 DAY);
Eg: currentdate BETWEEN admission.indate AND admission.outdate
This one works perfectly.
I cannot understand what is wrong with the previous one.
Well, the point is that currentdate is a table in the DB to enter the date I require for testing purposes not the system date. And it works ok. I think there is something wrong with the expression SUBDATE(`currentdate`, INTERVAL 365 DAY);
Eg: currentdate BETWEEN admission.indate AND admission.outdate
This one works perfectly.
I cannot understand what is wrong with the previous one.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you very much!
admission.indate between SUBDATE(`currentdate`, INTERVAL 365 DAY) and currentdate - correct!
admission.indate between SUBDATE(`currentdate`, INTERVAL 365 DAY) and currentdate - correct!