View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Jamie Collins Jamie Collins is offline
external usenet poster
 
Posts: 593
Default Adding "And" clause in SQL string causing SQL Syntax error

"Android" wrote ...

I am having a frustrating time finding why simply adding a "AND" clause
within my WHERE clause would cause a problem. I am getting an SQL syntax
error.


As I see it, you have two choices:

1) Build the query using the MS Query wizard while recording a macro,
as you originally did, and see what the SQL looks like (awful,
usually).
2) Write some proper SQL e.g. no need to alias the table if there is
only one table used (and what's the point in using the full table name
as the alias anyhow?!), the carriage returns are not needed, use an
unambiguous date format that your provider (did you say which one?)
recognizes as a valid date, use the BETWEEN syntax if your provider
supports it, etc. The SQL a human would write looks more like this
(provider = Jet):

sSql = "SELECT Confirmations AS dCategory, [Sender Name] AS dFrom," &
_
" Received AS dReceived, 1 AS dAllOnes" & _
" FROM [DONE confirmations] WHERE" & _
" Received BETWEEN #01 JUN 2004# AND #30 JUN 2004#;"

Jamie.

--