I cannot believe T-SQL doesn't have a median() function.
There are many people posting their own online, but many of them are not correct or at least not simple enough.
declare @varMedian table(
Median int,
ID int identity)
insert into @varMedian (Median)
select [Age]
from [@varPatientList]
order by [Age] ASC
declare @Count as int,@Median as int
(
Read more... )