title: Calculating days to excluding weekends (Monday to Friday) in SQL Server
body: <p>How can I calculate the number of work days between two dates from table (from the 1st row to the end) in SQL Server 2008? </p>
  
  <p>I tried something like this, but it does not work</p>
  
  <pre><code>DECLARE @StartDate as DATETIME, @EndDate as DATETIME
  
  Select @StartDate = date2 from testtable ;
  select @EndDate = date1 from testtable ;
  
  SELECT
     (DATEDIFF(dd, @StartDate, @EndDate) + 1)
    -(DATEDIFF(wk, @StartDate, @EndDate) * 2)
    -(CASE WHEN DATENAME(dw, @StartDate) = 'Sunday' THEN 1 ELSE 0 END)
    -(CASE WHEN DATENAME(dw, @EndDate) = 'Saturday' THEN 1 ELSE 0 END)
  </code></pre>