SQL 2000 UDF to return the age of a person, given a date of birth

SQL Server 2000 script for creating a user defined function that returns
the age of person whose date of birth has been provided.

To use the function:

SELECT dbname.dbo.GetAge(DateOfBirth, GETDATE()), column1, column2….,

FROM TableName

Alternatively

SELECT * FROM TableName

WHERE dbname.dbo.GetAge(DateOfBirth, GETDATE()) > n

Unfortunately SQL Server 2000 doesn’t allow for the use of GETDATE() within
user defined functions so it needs to be passed explicitly as a parameter.

Get the Script

Previous article
Next article

Get the Free Newsletter!

Subscribe to Cloud Insider for top news, trends & analysis

Latest Articles