General question on writing a complex query

  • Thread starter Thread starter Damon Heron
  • Start date Start date
D

Damon Heron

I have this query that is one of many in an option box that, if selected,
loads a listbox with the results. I have the AND and OR used several times
and that is where my problem is, I think. It seems to be ignoring the
"GroupID=0" part of the second half of the where conditions. Aside from
that problem, is there a logical way to group conditions when using AND and
OR statements, or can someone point me to a way to design a truth table
around all of this so I can quit wasting all this time experimenting?
Here is the sql stmt....


"SELECT tblContainer.ContainerID, tblContainer.ContainerName,
tblContainer.Capacity, tblContainer.ContainerTypeID,
tblContainer.LocationID, tblContainer.Gallons, tblContainer.Committed" & _
" FROM tblContainer WHERE ((tblContainer.Committed) = False) And
((tblContainer.BldID) = 0) And ((tblContainer.ContainerTypeID) <>2) And
((tblContainer.ContainerTypeID) <>6)" & _

" Or ((tblContainer.Capacity) <> ([tblContainer].[Gallons])) And
((tblContainer.BldID) = " & intBldID & ") And ((tblContainer.GroupID)=0)
ORDER BY tblContainer.Capacity, tblContainer.ContainerName"

Thanks for any and all suggestions...:)
 
You probably need to add a few ( & ) in your SQL. Remember back to your
first year algebra and combine AND and OR statements.

Try this --
SELECT tblContainer.ContainerID, tblContainer.ContainerName,
tblContainer.Capacity, tblContainer.ContainerTypeID,
tblContainer.LocationID, tblContainer.Gallons, tblContainer.Committed
FROM tblContainer
WHERE (tblContainer.Committed = False And tblContainer.BldID = 0 And
tblContainer.ContainerTypeID <>2 And
tblContainer.ContainerTypeID <>6) Or (tblContainer.Capacity <>
tblContainer.Gallons And tblContainer.BldID = intBldID And
tblContainer.GroupID =0)
ORDER BY tblContainer.Capacity, tblContainer.ContainerName
 
Thanks I will try that without parens.

--
Damon Heron
KARL DEWEY said:
You probably need to add a few ( & ) in your SQL. Remember back to your
first year algebra and combine AND and OR statements.

Try this --
SELECT tblContainer.ContainerID, tblContainer.ContainerName,
tblContainer.Capacity, tblContainer.ContainerTypeID,
tblContainer.LocationID, tblContainer.Gallons, tblContainer.Committed
FROM tblContainer
WHERE (tblContainer.Committed = False And tblContainer.BldID = 0 And
tblContainer.ContainerTypeID <>2 And
tblContainer.ContainerTypeID <>6) Or (tblContainer.Capacity <>
tblContainer.Gallons And tblContainer.BldID = intBldID And
tblContainer.GroupID =0)
ORDER BY tblContainer.Capacity, tblContainer.ContainerName


Damon Heron said:
I have this query that is one of many in an option box that, if selected,
loads a listbox with the results. I have the AND and OR used several
times
and that is where my problem is, I think. It seems to be ignoring the
"GroupID=0" part of the second half of the where conditions. Aside from
that problem, is there a logical way to group conditions when using AND
and
OR statements, or can someone point me to a way to design a truth table
around all of this so I can quit wasting all this time experimenting?
Here is the sql stmt....


"SELECT tblContainer.ContainerID, tblContainer.ContainerName,
tblContainer.Capacity, tblContainer.ContainerTypeID,
tblContainer.LocationID, tblContainer.Gallons, tblContainer.Committed" &
_
" FROM tblContainer WHERE ((tblContainer.Committed) = False) And
((tblContainer.BldID) = 0) And ((tblContainer.ContainerTypeID) <>2) And
((tblContainer.ContainerTypeID) <>6)" & _

" Or ((tblContainer.Capacity) <> ([tblContainer].[Gallons])) And
((tblContainer.BldID) = " & intBldID & ") And ((tblContainer.GroupID)=0)
ORDER BY tblContainer.Capacity, tblContainer.ContainerName"

Thanks for any and all suggestions...:)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top