Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

COnverting Crystal date formula in SQL server 2005

Status
Not open for further replies.

Zara9

IS-IT--Management
Aug 16, 2010
10
CA
Hi,
I have been stuck at this for sometime. I will appreciate if someone helps me. I have a date of birth column and one age column. In the final result I would like to see members turning 18 this year starting from today so today would be (1st of month...August 1st 2010). In crystal, the formula is: Year({table1.bdate}) <= Year(CurrentDate) - 18
Question is: how do I write this in sql.
I have something like this: (DATEDIFF(year, bdate, DATEADD(s, - 1, DATEADD(mm,DATEDIFF(m, 0, GETDATE()), 0))) = 18)
But this give me results of members turning 18 for the whole year including MArch, April etc.

 
Zara

Year is a SQL server function too.

Year(bdate) <= Year(getdate()) - 18

Ian
 
Ian thanks for replying. When I do use the Year(bdate) <= Year(getdate()) - 18
It gives me all the members with age greater than 18.

What I want is, members turning 18 this year starting from the current month. So, for this month it would start from August 1st.

and i dont know how to get it.. Plz help
Zara
 
Markros:

This give me members with age 18 and less..
I only want to see members turning 18 this year (starting from the current month)

:(
 
(DATEDIFF(year, bdate, DATEADD(s, - 1, DATEADD(mm,DATEDIFF(m, 0, GETDATE()), 0))) = 18)

This gives me closest results but only problem is that it starts from January not from current month.

Any suggestion to this one?
 
Thanks so much for helping me but this gives me nothing, no result at all.

hmm..
 
Still the same doesnt give me any result :/
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top