SQLTeam.com | Weblogs | Forums

SQL state for calculating age


#1

New to SQL server have two columns BIRTHDAY and AGE. Is there a statement to calculate the age from the BIRTHDAY column and enter it into the AGE column, any help would be appreciated.


#2

An AGE column is going to be out of date (at some point) isn't it?

If you need AGE probably better to have either a calculated column (rather than a column with a persistent value), or a VIEW that also includes the calculation.

	[AGE] = DATEDIFF(Year, BIRTHDAY, GetDate())
		- CASE WHEN DATEADD(Year 
					, DATEDIFF(Year, BIRTHDAY, GetDate())
					, BIRTHDAY)
				> GetDate() THEN 1
			ELSE 0
			END

#3

Thank you that got me started