locked
how to calculate age from DOB year RRS feed

  • Question

  • I am using this query year(getdate()) 
    - year(Patient_Birth_Year)
    - case when month(Patient_Birth_Year) > month(getdate()) then 1
               when month(Patient_Birth_Year) < month(getdate()) then 0
              when day(Patient_Birth_Year) >day(Patient_Birth_Year) then 1
    else 0
    end

    but I dont know weather its right or not actually its giving all the results the same answer
    like its showing all the patients the same age i.e 106 Dont know why


    can anybody just tell me how to deal with it
    or give me another query I just need to calculate age from DOB
    my DOB column name is  (Patient_Birth_Year)

    Tahir Ayoub
    Monday, November 14, 2011 5:36 AM

Answers

  • you cannot have a Select in Named Calculation.

    Have Something like

     

    Year(GETDATE())-Patient_Birth_Year

     


    vinu
    • Marked as answer by Tahir Ayoub Monday, November 14, 2011 3:41 PM
    Monday, November 14, 2011 3:35 PM

All replies


  • Tahir Ayoub
    Monday, November 14, 2011 5:39 AM
  • Hi Tahir,

    You are using Patient_Birth_Year which has datatype not as DateTime. Try to run below query and change values, everytime you will get the same 106 -

    select year(getdate())  
    - year(2089)
    - case when month(2001) > month(getdate()) then 1
               when month(2010) < month(getdate()) then 0
              when day(2010) >day(2010) then 1
    else 0
    end

    You can either try

    select year(getdate()) - Patient_Birth_Year as Patient_Age_Years

    or see below thread for how to evaluate it in generic way -

    http://social.msdn.microsoft.com/forums/en-US/transactsql/thread/399a7e87-bc78-47a5-8cc2-2d2436886fd7/

    HTH.

    Regards,
    Santosh


    It feels good if you give us some points for helpful post. :)

    Monday, November 14, 2011 5:45 AM

  • Tahir Ayoub
    Monday, November 14, 2011 2:46 PM
  • you cannot have a Select in Named Calculation.

    Have Something like

     

    Year(GETDATE())-Patient_Birth_Year

     


    vinu
    • Marked as answer by Tahir Ayoub Monday, November 14, 2011 3:41 PM
    Monday, November 14, 2011 3:35 PM
  • Thankx man thankx alot 

     


    Tahir Ayoub
    Monday, November 14, 2011 3:42 PM