title: T-SQL Script for count day
body: <p>I created a table which has this row of data:</p>
  
  <pre><code>WorkerID  StartDate  EndDate
  ========  =========  ==========
  0001      2019/11/1  2019/11/2
  </code></pre>
  
  <p>When I write the day different for worker 0001 on November/2019, is pretty easy by</p>
  
  <pre><code>SELECT WorkerID, [WorkingDay]= DATEDIFF(day, [EndDate], [StartDate]) 
  where [StartDate ] &gt;= '2019-11-1' and EndDate &lt;='2019-11-30'
  </code></pre>
  
  <p>however, if the record is that</p>
  
  <pre><code>WorkerID  StartDate   EndDate
  ========  =========   ==========
  0001      2019/11/29  2019/12/3
  </code></pre>
  
  <p>I will want the result table as below</p>
  
  <pre><code>WorkerID  Workday     WorkFirstDayOfMonth
  ========  =========   ===================
  0001      2            2019/11/1
  0001      3            2019/12/1
  </code></pre>
  
  <p>Can I know how write the T-SQL query? The appropriate <code>where</code> clause is</p>
  
  <pre><code>where [StartDate ] &gt;= '2019-11-1' and EndDate &lt;='2019-12-31'
  </code></pre>