title: Get specific from Zone - To Zone data - Sql server 2012
body: <p>I have one table name entrystate i only want those vehicle data which left X zone and Enter in (A,B,C,D,E) zone, O state mean left and 1 mean Enter in Zone</p>
  
  <pre><code>  ZoneId  VehId      TimeFirst                     State
      X       1    2016-07-01 00:39:25                 0
      x       2    2016-07-01 00:50:25                 0
      x       1    2016-07-01 00:52:25                 0
      x       2    2016-07-01 00:53:25                 0
      A       1    2016-07-02 12:50:25                 1
      A       1    2016-07-02 14:50:25                 1
      A       1    2016-07-04 15:50:25                 1
      f       3    2016-07-03 14:50:25                 0
      A       3    2016-07-04 14:50:25                 1
      B       2    2016-07-02 00:50:25                 1
  </code></pre>
  
  <p>required result </p>
  
  <pre><code>  fromZone  Tozone VehId      FromTime                   ToTime        
      X        A       1    2016-07-01 00:52:25         2016-07-02 12:50:25       
      x        B       2    2016-07-01 00:53:25         2016-07-02 00:50:25       
  </code></pre>