• As usual with age, leap year birthdays are the deciding factor.

    If someone was born on Feb 29, 2004, how old are they on Feb 28, 2018?  In your code, 13.  But in some jurisdictions, legally that person is 14 on Feb 28.  In other jurisdictions, you can use Mar-1 as their birthday in non-leap years.

    Edit: Btw, get rid of the variable in the function, it adds slight overhead unnecessarily:


    CREATE FUNCTION dbo.Age (@BornOn DATE, @AgeOn DATE)
    RETURNS int
    AS
    BEGIN
    RETURN (
      SELECT (CAST(CONVERT(VARCHAR(8), @AgeOn, 112) AS int) - CONVERT(VARCHAR(8), @BornOn, 112)) / 10000
    )
    END;

    SQL DBA,SQL Server MVP(07, 08, 09) A socialist is someone who will give you the shirt off *someone else's* back.