Link to home
Start Free TrialLog in
Avatar of anastasiasoul
anastasiasoulFlag for United Kingdom of Great Britain and Northern Ireland

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
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);

Open in new window

Avatar of Kim Ryan
Kim Ryan
Flag of Australia image

You don't need the back ticks, try CURRENT_DATE() or just  CURRENT_DATE
Avatar of anastasiasoul

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.
ASKER CERTIFIED SOLUTION
Avatar of Kim Ryan
Kim Ryan
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you very much!
admission.indate between SUBDATE(`currentdate`, INTERVAL 365 DAY) and currentdate - correct!