title: Subtract two rows of same table and sum the difference
body: <pre><code>OrNo    CurrentDate         PreviousDate        Finished    Amount
  G988    02.05.2013 14:00:47 NULL                False       1560
  G988    02.05.2013 21:30:00 02.05.2013 14:00:47 False       3170
  G988    03.05.2013 06:00:00 02.05.2013 21:30:00 False       5095
  G988    03.05.2013 07:46:24 03.05.2013 06:00:00 True        5254
  </code></pre>
  
  <p>Table Name: oldDate</p>
  
  <p>I have this data, and I have to calculate the total amount on a single day but I need to also subtract the previous day's amount, so that only the amount which was produced today (current date) is calculated. </p>
  
  <p>Current Date is the real date on which the order is processed and previous date is the last day's date on which this order was processed. Point me out if m not clear in explanation of the data, I tried .. </p>
  
  <pre><code>if t2.CurrentDate = t1.PreviousDate and datepart(t2.CurrentDate)= datepart(t1.CurrentDate) 
  
  then
       if t1.CurrentDate&gt;t2.CurrentDate
  
          then  @amount = t1.Amount
  
       else @amount = t2.Amount
  </code></pre>
  
  <p>I'm bad at dealing with joins .. :( so I have problems with this logic, I tried some other code from other examples but was not successful, any ideas will be really appreciated..</p>