title: Calculating in SQL the first working day of a given month
body: <p>I have to calculate all the invoices which have been paid in the first 'N' days of a month. I have two tables</p>
  
  <p>. INVOICE: it has the invoice information. The only field which does matter is called 'datePayment'</p>
  
  <p>. HOLYDAYS: It is a one column table. Entries at this table are of the form "2009-01-01",
    2009-05-01" and so on. </p>
  
  <p>I should consider also Saturdays and Sundays 
  (this might be not a problem because I could insert those days at the Hollidays table in order to consider them as hollidays if neccesary)</p>
  
  <p>The problem is to calculate which is the 'payment limit'.</p>
  
  <pre><code>select count(*) from invoice 
  where datePayment  &lt; PAYMENTLIMIT
  </code></pre>
  
  <p>My question is how to calculate this PAYMENTLIMIT. Where PAYMENTLIMIT is 'the fifth working day of every month'.</p>
  
  <p>The query should be run under Mysql and Oracle therefore standard SQL should be used.</p>
  
  <p>Any hint?</p>
  
  <p>EDIT
  In order to be consistent with the title of the question the pseudo-query should the read as follows:</p>
  
  <pre><code>select count(*) from invoice 
  where datePayment  &lt; FIRST_WORKING_DAY + N
  </code></pre>
  
  <p>then the question can be reduced to calculate the FIRST_WORKING_DAY of every month.</p>