title: How to diagnose syntax error from a parameterized SQL Server query in VBA ADODB
body: <p>I'm using VBA adodb to write <code>INSERT</code> statements in a SQL Server based on Excel row contents.</p>
  
  <p>I'm using parameterized queries so my VBA code has the following form:</p>
  
  <pre class="lang-vb prettyprint-override"><code>sqlStatement = "INSERT INTO dbo.mytable (" &amp; Join(insertElement(0), ", ") &amp; ") VALUES (" &amp; Join(insertElement(2), ", ") &amp; ")"
  Set cm = New ADODB.Command
  
  With cm
        Debug.Print (sqlStatement)
              .ActiveConnection = conn
              .CommandText = sqlStatement
              .CommandType = adCmdText
               For Each e In insertElement(1)
                  Set Pm = .CreateParameter(, adVarChar, 3, 1024, e)
                  .Parameters.Append Pm
               Next e
               Set rs = .Execute
          End With
  </code></pre>
  
  <p>where <code>insertElement(0)</code> is an array of field names, ...(1) is an array of values, and ...(2) is an array of placeholder <code>?</code>'s to support parameterization</p>
  
  <p>When I run this code, I get an error </p>
  
  <blockquote>
    <p>[Microsoft][ODBC Driver 13 for SQL Server][SQL Server] Incorrect syntax near 'Output'</p>
  </blockquote>
  
  <p>However, when I interrogate the <code>sqlStatement</code> text, there is no 'Output' anywhere in the statement. The text is of the form:</p>
  
  <pre><code>INSERT INTO dbo.mytable ([my_field_1],[my_field_2],[somefieldshaveweirdcharslike+#], ...) VALUES (?, ?, ?, ...) 
  </code></pre>
  
  <p>So, if I'm not providing the 'Output' command directly, and I can't directly see the statement because it's being processed on the server side, how can I diagnose the syntax?</p>