The queries look the same in designview??

  • Thread starter Thread starter Ann-Sofie Karlsson
  • Start date Start date
A

Ann-Sofie Karlsson

Hi

I have two queries that look the same in the the designview but has
different SQL code . The results from the queries are also different. I
wonder how they can look the same in designview but give different results.
What's the reason?? It should be in the SQL code but I can't see it.

Here are the two queries

SELECT MSysObjects.Name ,Type FROM MSysObjects
WHERE Not Type Is Null AND (Type=Forms!frmSLT!cboObjTypeFilter OR
Len(Forms!frmSLT!cboObjTypeFilter & '')=0) And Left$([Name],1)<>'~'
ORDER BY Type, MSysObjects.Name;

SELECT MSysObjects.Name , Type FROM MSysObjects
WHERE (Type=Forms!frmSLT!cboObjTypeFilter And Not Type Is Null) AND
Left$([Name],1)<>'~' OR Left$([Name],1)<>'~' AND
Len(Forms!frmSLT!cboObjTypeFilter)=0
ORDER BY Type, MSysObjects.Name;

Please help

Fia
 
So let me get this straight, this is the logic you want the query to work
through:

SELECT MSysObjects.Name ,Type FROM MSysObjects

WHERE

Type IS NOT NULL
AND
Type = Form value
OR
LEN(Type) = 0
AND
Left(Name,1) <> '~'


Well, both queries would do that as far as I can tell, but the grouping of
the operators is giving me a headache

However, having seen your queries previous, might I suggest that you try to
group the operators more clearly - as I think this is where your issues
extend from.

So I would write the query like, making it clear to me what grouping of
operators I am wanting:


SELECT MSysObjects.Name, Type FROM MSysObjects
WHERE
Type IS NOT NULL
AND
LEFT$([Name],1) <> "~"
AND
(
(Type = Form value)
OR
(LEN(Form Value) = 0)
)

ORDER BY Type, MSysObjects.Name;
 
These queries don't look the same in design view in A2003.

On the 2nd Criteria line under the Type field, the first query has:
Not Is Null
where the 2nd one does not.

These queries have unbracketed AND and OR phrases in the WHERE clause. You
need to be aware that:
a AND (b OR c)
is not the same as:
(a AND b) OR c
 
Back
Top