Quote:
there is no syntax error in the query, its a logic error, i mean the query gives result but when you check not all results are true. for example in above query i used Year([dat_birthday])this will return the value of year as integer. check this function,
IIf(Year([dat_diagnosisdate])-Year([dat_birthday])<=1,"True","False")
this function in a query will subtract the two years as integer values and if the difference is less or equals to one, then it will return true and if the difference is greater than one, it will return false.
Since i wanted a condition that i can play with ages less than a year, like a 1 month age to 12 months age, then in the iif(condition,"true","false") i had to nest another iif() if the the age is less or equals to one. that is iif(year(condition),iif(month(condition),"true","false"),"false") with this, now i could specify if i want lets say age less than eight months then in my query I'll have iif() as follows;
IIf(Year([dat_diagnosisdate])-Year([dat_birthday])<=1,IIf((MONTH([dat_diagnosisdate]))-(Month([dat_birthday]))<8,"true","false"),"false") as Age.
this was still giving me logic error, since it does not consider the whole date difference, that is if date of birth is 07/24/2012 and date diagnosed is 06/03/2013, the actual age should be 11months but with this function it could not calculate like that, instead it returns as -1 and year difference is equal to one, then it passed the conditions in iif() above.
but after trying to search more functions that can be used to calculate dates, i came to find the DateDiff(). I could simply use this to find difference in two dates and return values in either year,months,weeks,hours,seconds etc.
So the correct solution was as follows;
SELECT diagnosis.txt_TypeOfVisit, PatientPersonalData.dat_birthday, PatientPersonalData.txt_sex, diagnosis.dat_diagnosisdate,
IIf((datediff("m",[dat_birthday],[dat_diagnosisdate]))< 2,"lessthan","greaterthan") As AgeRang1
FROM diagnosis INNER JOIN PatientPersonalData ON diagnosis.ipnr = PatientPersonalData.Ipnr
WHERE (((diagnosis.txt_TypeOfVisit)="Revisit") AND ((PatientPersonalData.txt_sex)="F"));
Any ways thanks a lot guys for your support. Its nice to know that you are not working alone, ;)