title: Show values with specific status
body: <p>So I am running the following query:   </p>
  
  <pre><code>Select a.Location, ProcType, Status, f.Code, p.Day, Start, Stop, 
  (Case When Stop IS NULL then Start else  Stop end) as LastState, 
  (case when Type like 'Type1%' then Status else 'NULL' end) as Type1,
  (case when Type like 'Type2%' then Status else 'NULL' end) as Type2
  from dbo.table1 a
  inner join Database..table2 p on Name = 'RunDay' and 
  a.Location = p.Location and p.Value = a.SomeRunDay
  left outer join [Database].[dbo].[table3] f on a.File_number = 
  f.File_number 
  where a.Location is not NULL
  ORDER BY Location
  </code></pre>
  
  <p>And the results generated are:
  ** This table only shows values for one location, I have hundreds of them in my table</p>
  
  <pre><code>------------------------------------------------------------------------------|Location|ProcType|Status|Code| Day | Start | Stop |LastState|Type1|Type2| 
  ------------------------------------------------------------------------------
  |1 |Type1_A|Done| A |2018/03/01|15:58|16:32|2018/03/01 16:32|Done|NULL| 
  ------------------------------------------------------------------------------
  |1 |Type1_B|Done| B |2018/03/01|15:59|16:32|2018/03/01 16:34|Done|NULL| 
  ------------------------------------------------------------------------------
  |1 |Type2_A_Loop|Done| A |2018/03/01|16:00|16:38|2018/03/01 16:38|NULL|Done| 
  -------------------------------------------------------------------------------- 
  |1 |Type1_A_Loop|Processing| B |2018/03/11|15:59|16:32|2018/03/11 16:34|NULL|Processing|
  --------------------------------------------------------------------------------
  |1 |Type2_B|Processing| B |2018/03/11|15:59|16:32|2018/03/11 16:34|NULL|Processing|
  ------------------------------------------------------------------------
  </code></pre>
  
  <p>I am trying to find a way to view only the latest <code>ProcType</code>, the ones that show
  <code>Processing</code> taking into consideration that the <code>LastState</code> column is showing the most recent state. In other words, I want to see results that contain 'loop' only with the <code>Processing</code> status.</p>
  
  <p>The solution that is running in my head would be something like </p>
  
  <pre><code>Select MAX (LastState) from dbo.table1
  Where Status = 'Done'
  </code></pre>
  
  <p>and perform some sort of union..? I need some help with this.</p>
  
  <p>Thanks</p>