title: How to get total time between two dates based on condition in SQL Server 2008 while data inserting continuously by service?
body: <p>I want <code>outtime</code> column data like below:</p>
  
  <pre><code>vehicle Condition       Synctime                  outtime(hours)
  ----------------------------------------------------------------
  1              1        2017-09-20 8:30:10         null
  1              0        2017-09-20 10:30:10        2
  2              1        2017-09-19 8:30:10         null
  1              1        2017-09-20 13:30:10       
  1              0        2017-09-20 15:30:10        2
  2              0        2017-09-19 10:30:10
  1              1        2017-09-20 18:30:10
  2              1        2017-09-19 12:30:10        2
  </code></pre>
  
  <p>Here I want to get total time between times based on condition(1-in 0-out) and  vehicle(when vehicle <strong>out</strong> and when it is <strong>in</strong>).data ll inserting continuously as shown above. How can I achieve? Please help me. </p>