using SQL Build an procedure to calculate Age, the year of birth will be entered when the procedure is called. ***The current year will be brought from within the system.
**I request you to please provide a positive rating.**
Answer)
DECLARE @dateofbirth datetime
SET @dateofbirth ='1992-01-09 00:00:00'
SELECT DATEDIFF(hour,@dateofbirth ,GETDATE())/8766.0 AS
AgeYearsDecimal
,CONVERT(int,ROUND(DATEDIFF(hour,@dateofbirth
,GETDATE())/8766.0,0)) AS AgeYearsIntRounded
,DATEDIFF(hour,@dateofbirth ,GETDATE())/8766 AS
AgeYearsIntTruncated
By executing the above procedure, we can get the Output as below
AgeYearsDecimal :17.767054
AgeYearsIntRounded:18
AgeYearsIntTruncated : 17
Get Answers For Free
Most questions answered within 1 hours.