title: Calculate amount between period
body: <p>Help please !!!</p>
  
  <p>how to calculate the PayedManualAmount by period, the period is between Disbursement.
  so in the second Disbursement(325) i have to obtain 5
  in third Disbursement(500) i have to obtain 7 and so on..</p>
  
  <pre><code>if(OBJECT_ID('tempdb..#Amount') IS NOT NULL)
      drop table #Amount
  
  create table #Amount
  (
      Date                smalldatetime,
      Disbursement        decimal(18,2),
      PayedManualAmount   decimal(18,2),
      ForPayAmount        decimal(18,2)
  )
  
  
  INSERT INTO #AmountForPay(Date,Disbursement,PayedManualAmount,ForPayAmount) 
  VALUES
  ('20121226',    675.00  ,NULL   ,8.37),
  ('20121226',    NULL    ,5.00   ,0.00),
  ('20121227',    NULL    ,NULL   ,0.00),
  ('20121228',    NULL    ,NULL   ,0.00),
  ('20130323',    NULL    ,NULL   ,0.00),
  ('20130324',    NULL    ,NULL   ,0.00),
  ('20130325',    NULL    ,NULL   ,0.00),
  ('20130326',    NULL    ,NULL   ,0.00),
  ('20130327',    325.00  ,NULL   ,4.03),--ForPayAmount = SUM(PayedManualAmount) between 2012-12-26 and 2013-03-26 = 5
  ('20130328',    NULL    ,4      ,0.00),
  ('20130329',    NULL    ,NULL   ,0.00),
  ('20140228',    NULL    ,3      ,0.00),
  ('20140301',    NULL    ,NULL   ,0.00),
  ('20140302',    500.00  ,NULL   ,6.20), --ForPayAmount = SUM(PayedManualAmount) between 2013-03-27 and 2014-03-01 = 7 
  </code></pre>