Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Correct Age calculation Expand / Collapse
Author
Message
Posted Friday, January 06, 2012 2:52 PM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: 2 days ago @ 1:56 PM
Points: 267, Visits: 424
We are using the following to calculate age:

It doesn't seem correct ?
Any ideas would be great?

Thanks
Joe

INSERT INTO @TEMPTABLE(TAG_NAME,TAG_DATA)
SELECT TAG_NAME = 'CUST_AGE', TAG_DATA = (SELECT DATEDIFF (yy,bdate, GETDATE())FROM client
WHERE Client.OID =@CLIENT_OID);
Post #1231756
Posted Friday, January 06, 2012 2:59 PM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Monday, April 14, 2014 7:26 AM
Points: 1,949, Visits: 8,291
Hi

Try this post from my blog

http://sqlblogcasts.com/blogs/sqlandthelike/archive/2009/12/08/age-calculation-with-sql-server.aspx




Clear Sky SQL
My Blog
Kent user group
Post #1231759
Posted Saturday, January 07, 2012 10:42 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Wednesday, February 01, 2012 3:57 AM
Points: 91, Visits: 125
Here is good article for calculating age.

http://www.sqlservercentral.com/articles/T-SQL/63351/
Post #1231929
Posted Tuesday, January 10, 2012 9:00 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: 2 days ago @ 1:56 PM
Points: 267, Visits: 424
Thanks,

That works great, but Im new at SQL and have tried but can't get the syntax right..
What if I wanted to select bdate from the "Client" file as date1 and getdate() as date2 ?

Thanks
Joe
Post #1233312
Posted Thursday, January 12, 2012 7:25 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: 2 days ago @ 4:40 PM
Points: 177, Visits: 978
This is how I do it...

select c.clientid, convert(char(10),c.dateofbirth,101) as DOB,
case
when ((MONTH(c.dateofbirth) * 100) + DAY(c.dateofbirth)) > ((MONTH(getdate()) * 100) + DAY(getdate()))
then DATEDIFF(year,c.dateofbirth,getdate()) - 1
else DATEDIFF(year,c.dateofbirth,getdate()) End As Age
from clients c
Post #1234806
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse