Query Problem

S

Stephen Lynch

Help, I cannot figure this out.

I have a group by query and I am having problems with multiple OR
statements. When I save the query it puts each parameter on a seperate line
and then it doesn't work properly.

My parameter criteria is: Not Like "*9303*" Or Not Like ";S1C *" on field
Comments with another parameter of "wdl" on TransactionCode.

After I save, It drops each criteria to a seperate line and the results come
out wrong.

Here's what I start with that works;

SELECT tblTransactions.AccNumber, tblTransactions.FileDate AS CurrentDate,
tblPlans.PlanName, Sum(tblTransactions.DollarAmt) AS SumOfDollarAmt
FROM tblPlans INNER JOIN tblTransactions ON tblPlans.[SchwabAccNo] =
tblTransactions.AccNumber
WHERE (((tblTransactions.Comments) Not Like "*9303*" Or
(tblTransactions.Comments) Not Like ";S1C *") AND
((tblTransactions.TransactionCode)="wdl"))
GROUP BY tblTransactions.AccNumber, tblTransactions.FileDate,
tblPlans.PlanName
ORDER BY tblTransactions.FileDate DESC , tblPlans.PlanName;

Here's what it converts it to on save:

SELECT tblTransactions.AccNumber, tblTransactions.FileDate AS CurrentDate,
tblPlans.PlanName, Sum(tblTransactions.DollarAmt) AS SumOfDollarAmt
FROM tblPlans INNER JOIN tblTransactions ON tblPlans.[SchwabAccNo] =
tblTransactions.AccNumber
WHERE (((tblTransactions.Comments) Not Like "*9303*") AND
((tblTransactions.TransactionCode)="wdl")) OR (((tblTransactions.Comments)
Like ";S1C *") AND ((tblTransactions.TransactionCode)="wdl"))
GROUP BY tblTransactions.AccNumber, tblTransactions.FileDate,
tblPlans.PlanName
ORDER BY tblTransactions.FileDate DESC , tblPlans.PlanName;
 
J

Jim Burke in Novi

It doesn't make sense to say

(tblTransactions.Comments) Not Like "*9303*" Or
(tblTransactions.Comments) Not Like ";S1C *"

because it will evaluate to True every time - one of those has to be true
always. I'm not sure what logic you're trying to implement. If you want to
say that Comments should not be like either one of those strings, you need to
use AND instead of OR.
 

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


Top