title: MS ACCESS SQL query Excel sheet
body: <pre><code>SELECT f.card_serial_num, count(1) AS CardRxCnt
  FROM [Excel 8.0;HDR=Yes;Database=C:\Users\Mike\Desktop\er.xls].[er$] AS f
  WHERE f.location_name not like 'PREPACK' 
    and f.card_type not in ('PRN','sequential') 
    and (f.card_due_date = #9/15/2014# or f.card_due_date = #10/1/2014#)
  GROUP BY f.card_serial_num
  HAVING CardRxCnt &gt;2
  </code></pre>
  
  <p>I have a problem with <code>HAVING CardRxCnt &gt;2</code>. If I take out, I get my query returned.
  But if I have it in, it somehow prompts for an input and so when I just put 1 it
  returns nothing. Actually without <code>CardRxCnt</code>, sometimes the query prompts
  for an input at which I enter 1 and the query executes. Yet other times it would just go through. So my question is two part:</p>
  
  <ol>
  <li><p>what could be causing this random behavior of "asking"? I know to prompt for a user input, I have to surround a value with []. Could it be the Excel part?</p></li>
  <li><p><code>CardRxCnt</code> (in <code>SELECT</code> and <code>HAVING</code>): I don't see what's wrong with it but when I add this, query does not work.</p></li>
  </ol>
  
  <p>Please help. And I can't do VBA/macro here so if you're gonna say why don't you query with VBA it's not a solution for me.</p>