title: Coalesce over Rows in MSSQL 2008,
body: <p>I'm trying to determine the best approach here in MSSQL 2008.</p>
  
  <p>Here is my sample data</p>
  
  <pre><code>TransDate  Id     Active
  -------------------------
  1/18 1pm   5      1    
  1/18 2pm   5      0    
  1/18 3pm   5      Null    
  1/18 4pm   5      1    
  1/18 5pm   5      0    
  1/18 6pm   5      Null
  </code></pre>
  
  <p>If grouped by Id and ordered by the TransDate, I want the last Non Null Value for the Active Column, and the MAX of TransDate</p>
  
  <pre><code>SELECT MAX(TransDate) AS TransDate, 
         Id,
         --LASTNonNull(Active) AS Active
  </code></pre>
  
  <p>Here would be the results:</p>
  
  <pre><code>TransDate  Id  Active
  ---------------------    
  1/18 6pm   5   0
  </code></pre>
  
  <p>It would be like a Coalesce but over the rows, instead of two values/columns.</p>
  
  <p>There would be many other columns that would also have this similiar method applied, so I really don't want to make a seperate join for each of the columns.</p>
  
  <p>Any ideas?</p>