title: Selecting max/min value from more than one fields
body: <p>In the following query the start/finish columns are datetime fields. </p>
  
  <p>How should I modify this query to get two more columns, one with the min date and one with the max date (of all the 6 datetime fields and all the rows) repeated in each row. </p>
  
  <p>Alternatively how could I create a new query returning only these 2 (min/max) dates, for the same resultset of course? </p>
  
  <p>Thanks a lot! (I would like answers for both SQL Server 2005 and Sybase ASE 12.5.4) </p>
  
  <pre><code>select  erg_mst.code, 
          erg_types.perigrafh, 
          erg_mst.FirstBaseStart, 
          erg_mst.FirstBaseFinish,
          erg_mst.LastBaseStart, 
          erg_mst.LastBaseFinish ,
          erg_mst.ActualStart, 
          erg_mst.ActualFinish 
  from    erg_mst inner join 
          erg_types  on erg_mst.type = erg_types.type_code  
  where   erg_mst.activemodule = 'co' 
  and     (
              FirstBaseStart &lt;&gt; NULL OR 
              FirstBaseFinish &lt;&gt; NULL OR  
              LastBaseStart &lt;&gt; NULL OR 
              LastBaseFinish &lt;&gt; NULL OR 
              ActualStart &lt;&gt; NULL OR 
              ActualFinish &lt;&gt; NULL 
          )  
  order by    isnull(FirstBaseStart,isnull(LastBaseStart,ActualStart))
  </code></pre>