• Adam Gojdas (5/28/2010)


    Another way to calculate the age is:

    SELECT (ABS(CAST(CONVERT(char(8),GETDATE(),112) AS int)

    - CAST(CONVERT(char(8),@DOB,112) AS int)) / 10000) [AGE];

    Here is a link to where I originally saw this type of calculation. It is in the comments section. :

    http://www.sqlmag.com/article/tsql3/datetime-calculations-part-5.aspx

    Careful now... Because of the date conversions to the CHAR datatype, that will be relatively slow.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)