title: Function to Calculate Median in SQL Server
body: <p>According to <a href="http://msdn.microsoft.com/en-us/library/ms173454.aspx" rel="noreferrer">MSDN</a>, Median is not available as an aggregate function in Transact-SQL. However, I would like to find out whether it is possible to create this functionality (using the <a href="http://msdn.microsoft.com/en-us/library/ms182741.aspx" rel="noreferrer">Create Aggregate</a> function, user defined function, or some other method). </p>
  
  <p>What would be the best way (if possible) to do this - allow for the calculation of a median value (assuming a numeric data type) in an aggregate query?</p>