title: SQL SELECT / CASE query with multiple columns returns System Error: &H80040E14 (-2147217900)
body: <p>Good morning,</p>
  
  <p>I am having trouble with using <code>CASE</code> in a <code>SELECT</code> statement. The code works fine without it, even testing out the <code>CHARINDEX</code> works out. I've also substituted the code for more simpler <code>CASE</code> statements.</p>
  
  <p>What I am trying to do is <code>SELECT</code> two columns with an additional place-holder column in a different location depending on if <code>a.AH_NAME1</code> contains the string "KGa". The reason for this is because I'm automating a pre-existing Excel worksheet wherein they have values for non-inhouse orders one column over. That is where <code>'' AS placeholder</code> comes in.</p>
  
  <p>My error message is </p>
  
  <blockquote>
    <p>System Error: &amp;H80040E14 (-2147217900)</p>
  </blockquote>
  
  <pre><code>strSQL = "SELECT a.ID, a.AH_NAME1, b.FI_PREIS_ME, CASE WHEN CHARINDEX('KGa', a.AH_NAME1) &gt; 0 THEN (b.FI_NETTO, '' AS placeholder, a.DATUM_ERF) ELSE ('' AS placeholder, b.FI_NETTO, a.DATUM_ERF) END AS CHARGEA, CHARGEB, DATUM_ERF "
          strSQL = strSQL &amp; "FROM SYSADM.BW_AUFTR_KOPF a JOIN SYSADM.BW_AUFTR_POS b ON a.ID = b.ID "
          strSQL = strSQL &amp; "WHERE b.PROD_ID = '99999999' "
          strSQL = strSQL &amp; "AND a.STATUS BETWEEN 110 AND 860 "
          strSQL = strSQL &amp; "AND MONTH(a.DATUM_ERF) BETWEEN " &amp; Month(StartofMonth) &amp; " AND " &amp; Month(EndofMonth)
          strSQL = strSQL &amp; "AND YEAR(a.DATUM_ERF) BETWEEN " &amp; Year(StartofMonth) &amp; " AND " &amp; Year(EndofMonth)
  </code></pre>