title: SQL Server 2008 - Sum business minutes between two dates taking into account custom holidays and weekends
body: <p>Using SQL Server 2008, I need to sum the business minutes between two datetime fields, while taking into consideration non working hours and weekends/company holidays. I would like to incorporate a calendar if possible so that should I need to edit any holiday it could be easily done.</p>
  
  <p>E.g.</p>
  
  <pre><code>OpenCall              CloseCall 
  05/08/2013 14:00:00   06/08/2013 09:30:00             
  </code></pre>
  
  <p>The result for the above, needs to return: 240 -- (4 hours) working hours are: 08:30-17:00.</p>
  
  <p>If the call was open on Friday and was closed on Tuesday, then it should only calculate the minutes between the working hours on Friday, Monday and Tuesday (i.e not the weekend).</p>
  
  <p>I'm new to SQL/T-SQL so please explain any code/variables clearly - IF you can find a neat solution!</p>
  
  <p>Thanks in advance!</p>