title: SQL Server: Select minimum between two values in a SUM
body: <p>I'd appreciate if someone could help me with this SQL statement. I currently have this:</p>
  
  <pre><code>select sum(datediff(second, [date1], [date2])) from [MyTable] where &lt;condition&gt;
  </code></pre>
  
  <p>But I need to refine this selection, i.e. if the difference between dates is greater than @MaxDiffSecs then the @MaxDiffSecs should be used for summation instead. I tried looking into the MIN operator but it has only one parameter, where I'd expect at least 2 to get the minimum of.</p>
  
  <p>Well, anyway, thanks in advance. (I guess you can tell that I'm not really efficient at SQL :)</p>