Start Free Trial
Come for the solution, stay for everything else.
Start Free Trial
Calculate Age in SQL Server Express
In SQL Server Express 2017, I want to calculate Age in a table containing 100 records.
Let us say different DOBs are saved some 25 years before today. In the new column Age, this result is desired 25y 5m 3d.
Microsoft SQL Server
8/22/2022 - Mon
That article should help.
ASKER CERTIFIED SOLUTION
Log in or sign up to see answer
Become an EE member today
7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Both answers can be tweaked to arrive at a combined result.
However, it requires a little long code to find the answer.
This is a result in years and months.
Update statement is applied to update AccountAge checking AccountOpenDate compared with current date.
Set AccountAge = Str(DateDiff(YEAR,AccountO
Date) <= Month(GetDate()),0,1),2,0)
+ 'y ' + Str(IIF(Month(AccountOpenD
ate) <= Month(GetDate()), Month(GetDate())-Month(Acc
0) + 'm'
I assumed you wanted the age in years only.
By the way, why are you storing the age in a table?
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
On a monthly basis, the Account age is to be calculated, so that based on age of the account, the processes can be carried out. For example, mapping some plans and sharing them with the Customers based on the age of the their account. So it will be easy to work on saved age of the Account.
If that's the case you shouldn't be updating the age every month in the table, you should use a query that returns the age and use that.
Why not create a view that contains the age calculation?
to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Plans and Pricing
Certified Expert Program
© 1996-2022 Experts Exchange, LLC. All rights reserved. Covered by US Patent