title: Access VBA Error 3075 Syntax Error (missing operator)
body: <p>I seem to continually run in to problems when setting a string as and SQL statement I had pre-written in SSMS.</p>
  
  <p>I have 2 questions which are both related. First, I only seem to run in to problems when dealing with a bit more complex queries (several joins, where conditions, correlated sub queries, and case statements) as a opposed to simple queries. Anyone have any good resources where I can read about syntax 'rules' when writing queries in SSMS to VBA?</p>
  
  <p>Second, below is an example of a query I wrote in the AdventureWorks sample DB that gives me the error listed in the title of this question. My T-SQL statement is:</p>
  
  <pre><code>sSQL = "SELECT ba.BusinessEntityID,ba.AddressID
                ,(CASE WHEN ba.BusinessEntityID &gt; 5
                  THEN
                  (SELECT pp.FirstName FROM [Person].[Person] pp
                  WHERE pp.BusinessEntityID = ba.BusinessEntityID)
                 Else 'AA' END) AS 'TEST'
          FROM Person.BusinessEntityAddress ba
          INNER JOIN person.AddressType at ON at.AddressTypeID = ba.AddressTypeID
          WHERE ba.BusinessEntityID &lt; 11;"
  </code></pre>
  
  <p>Error occurs on line "Set rs = db.OpenRecordset(sSQL, dbOpenDynaset, dbSeeChanges)" which says:</p>
  
  <p>"Run-Time Error 3075 Syntax Error (missing operator) in query expression '(CASE WHEN ba.BusinessEntityID > 5
                      THEN
                      (SELECT pp.FirstName FROM [Person].[Person] pp
                      WHERE pp.BusinessEntityID = ba.BusinessEntityID)
                     Else 'AA' END) AS 'TEST'"</p>