By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,689 Members | 1,901 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,689 IT Pros & Developers. It's quick & easy.

sum() function - need help

P: 2
Hi,

When i used sum() function in the SQL queries in MS Access for calculating the age of people in a database. i can able to get the result but the result comes out with a minus (negative) sign in front of it..
I had posted my SQL query below

select sum(year(now())-year([date_of_birth])<30) as Less_than_30, sum(year(now())-year([date_of_birth])>=30) as 30_and_more from students

Can anyone please explain about this and suggest a solution..

Thank You

Arvind
Oct 3 '06 #1
Share this Question
Share on Google+
2 Replies


100+
P: 143
Try this function instead.

Public Function MyAge(dteDOB As Date, Optional SpecDate As Variant) As Integer
Dim dteBase As Date, intCurrent As Date, intEstAge As Integer
If IsMissing(SpecDate) Then
dteBase = Date
Else
dteBase = SpecDate
End If
intEstAge = DateDiff("yyyy", dteDOB, dteBase)
intCurrent = DateSerial(Year(dteBase), Month(dteDOB), Day(dteDOB))
MyAge = intEstAge + (dteBase < intCurrent)
End Function

Call it in a query like so

MyAge([YourDateField])
Oct 3 '06 #2

P: 2
Try this function instead.

Public Function MyAge(dteDOB As Date, Optional SpecDate As Variant) As Integer
Dim dteBase As Date, intCurrent As Date, intEstAge As Integer
If IsMissing(SpecDate) Then
dteBase = Date
Else
dteBase = SpecDate
End If
intEstAge = DateDiff("yyyy", dteDOB, dteBase)
intCurrent = DateSerial(Year(dteBase), Month(dteDOB), Day(dteDOB))
MyAge = intEstAge + (dteBase < intCurrent)
End Function

Call it in a query like so

MyAge([YourDateField])

Thank You

Arvind
Oct 5 '06 #3

Post your reply

Sign in to post your reply or Sign up for a free account.