Issue with Not Equal to in Query (1 Viewer)

randolphoralph

Registered User.
Local time
Yesterday, 20:00
Joined
Aug 4, 2008
Messages
101
I am trying to get a count of Claim and Sum of Paid Amt where the Rend field is not equal to A6, A7, A8, DF, 26, 62, 77, 91, 93, 94, or 96.

The issue I am having is when I run the query it is giving me count and sum from all the records. I am not sure what I have done incorrectly.

Here is the SQL for the query.



Code:
SELECT Count([2005].[CLAIM]) AS [CountOfCLAIM], Sum([2005].[PAID AMT]) AS [SumOfPAID AMT] INTO ClaimTotal
FROM 2005
WHERE ((([2005].[REND])<>"A6" Or ([2005].[REND])<>"A7" Or ([2005].[REND])<>"A8" Or ([2005].[REND])<>"DF" Or ([2005].[REND])<>"26" Or ([2005].[REND])<>"62" Or ([2005].[REND])<>"77" Or ([2005].[REND])<>"91" Or ([2005].[REND])<>"93" Or ([2005].[REND])<>"94" Or ([2005].[REND])<>"96"));
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 18:00
Joined
Aug 30, 2003
Messages
36,127
Try And instead of Or. With Or, anything is either not equal to A or not equal to B.
 

boblarson

Smeghead
Local time
Yesterday, 18:00
Joined
Jan 12, 2001
Messages
32,059
1. you don't use OR between the numbers. You need AND.

2. But a better way is NOT IN.


FROM 2005
WHERE [2005].[REND] NOT IN ("A6"."A7","A8","DF","26","62","77","91","93","94","96");
 

randolphoralph

Registered User.
Local time
Yesterday, 20:00
Joined
Aug 4, 2008
Messages
101
Thanks both of you. That always gets me cause you use Or when you are looking at Equal to....and I forget to use And when looking for Not Equal to.
 

Users who are viewing this thread

Top Bottom