Hii friends
I need to calculate the age median from the given dates of birth in an employee database in MS SQl.
Please help...
Roma
Hi,
for calculating the age use the following sample query and change it according to your requirement
DECLARE @FromDate DATETIME,
@ToDate DATETIME
SELECT @FromDate = '1983-07-04',@ToDate = '2008-07-04'
SELECT CASE WHEN @FromDate > @ToDate THEN NULL
WHEN DATEPART(day, @FromDate) > DATEPART(day, @ToDate) THEN DATEDIFF(month, @FromDate, @ToDate) - 1
ELSE DATEDIFF(month, @FromDate, @ToDate)
END / 12.0
thanks