title: Math calculating min or max for more than two columns
body: <p>I found this on <a href="https://stackoverflow.com/questions/124417/is-there-a-max-function-in-sql-server-that-takes-two-values-like-math-max-in-ne">here</a> by splattne, but couldn't post a comment asking the following question, so here it is.</p>
  
  <pre><code>-- the following expression calculates ==&gt; max(@val1, @val2)
  SELECT 0.5 * ((@val1 + @val2) + ABS(@val1 - @val2)) 
  </code></pre>
  
  <p>What would this formula look like to get the minimum?</p>
  
  <p>What would this formula look like for 4 columns?  (I know, more than one question.)</p>