title: "neater" way of counting holidays
body: <p>I have a neat table of holidays showing date and recurrence if such holiday is recurrent (i.e. New Year)</p>
  
  <p><img src="https://i.stack.imgur.com/TzRqT.png" alt="enter image description here"></p>
  
  <p>Now, I need to count the number of holidays between two dates. If it was a simple list of dates without info about recurrence (so i.e. it would show all New Years between 2000-01-01 and 2015-01-01) it would be quite easy, i.e. something like</p>
  
  <pre><code>declare @start_Date Date= '2013-01-02',
  @end_date Date ='2014-01-02'
  
  
  
  SELECT  COUNT(CE.name) AS holidays_count
  FROM dbo.argo_cal_event AS CE INNER JOIN  dbo.argo_cal_event_type AS CET 
  ON CE.event_type_gkey = CET.gkey
  WHERE (CET.name = 'EXEMPT_DAY') AND (CE.name &lt;&gt; 'Sundays')
  AND (CE.occ_start BETWEEN @start_Date AND @end_date) 
  </code></pre>
  
  <p>But now we have a neat recurrence, so the query above won't count all the New Years, Christmases etc that have been declared as happening "every year starting from".</p>
  
  <p>I <em>COULD</em> create a table with such list, but I've been wondering, is there any other way?</p>
  
  <p>EDIT: Let me precise what I had in mind: I'd like to count the event normally if it event occurs once (I will assume here that user will have to populate all the irregular holidays as i.e. Easter), but when the recurrence &lt;> Once, then get the occurrence start and count the years between that date and final date. </p>
  
  <p>EDIT2: I think I've got it - for the recurrent holidays I can use</p>
  
  <pre><code>SELECT sum (datediff (year, ce.occ_start, @end_date)) as recurrent_holidays
  FROM dbo.argo_cal_event AS CE INNER JOIN  dbo.argo_cal_event_type AS CET 
  ON CE.event_type_gkey = CET.gkey
   WHERE (CET.name = 'EXEMPT_DAY') and (CE.repeat_interval ='ANNUALLY')
  </code></pre>
  
  <p>EDIT3: unfortunately this solution doesn't work (or at least getting quite complicated) if I'd like to count between TWO dates, in which one is taken from another table, i.e if I'd like to count recurring holidays between unit.time_in and getddate() :/</p>