View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
imillicit imillicit is offline
external usenet poster
 
Posts: 3
Default Inconsistent results with Query

I am retrieving data from a Visual Foxpro database, via ODBC using a VBA
macro to populate a worksheet. I wish to select all records which match a
(slightly complex) set of criteria for an item code.

Either 6-digits
* I'm using LIKE '??????' to achieve this
or beginning with S but not SC
* I'm using (LIKE 'S%' and NOT LIKE 'SC%')

The actual boolean expression is:

WHERE (cn_ref LIKE '??????' or (cn_ref LIKE 'S%' and NOT cn_ref LIKE 'SC%'))

When I use this expression in MS query (or via VBA) I only get records that
match the second condition but when I use this from MS Access (2007), I get
the full set of records I expect. I notice that in MSQ the SQL statement is
re-written slightly but I can't see this being the problem.

I even tried rewriting the query as the union of two individual select
statements to see if MS Query could do as I ask but again, I only got the
second set of data. This wasn't because the union was a sensible way to
retrieve this data but because I couldn't see why two MS products failed to
return the same data set.

Does anybody have any ideas either how to change the logic in my where
clause or achieve the results I'm after in a simpler way that MS Query can
understand?

Thanks,
Ian