Hello.I have three INT columns in a table that record the users birth year, month, and day. BDAY_DAY (INT)BDAY_YEAR (INT)BDAY_MONTH (INT)I'd like to include a function in my query that will return their Age in years based on these three columns.I found this function on the internets, but I'm not sure how to build a DATETIME object using the three int date columns to pass to the function. If you could help me there it'd be most appriciated.Create FUNCTION dbo.GetAge (@DOB datetime, @Today Datetime) RETURNS IntASBeginDeclare @Age As IntSet @Age = Year(@Today) - Year(@DOB)If Month(@Today) < Month(@DOB)Set @Age = @Age -1If Month(@Today) = Month(@DOB) and Day(@Today) < Day(@DOB)Set @Age = @Age - 1Return @AGEEnd
Usage (how do i pass the three columns into this function??)SELECT Last_Name, First_Name, ssn, dobFROM Employee_Data e (nolock)WHERE Cust_Id = 'Customer1'and dbo.GetAge(e.Date_Of_Birth, getdate()) >= 21