'OR' Function in a Query

jcbhydro

Registered User.
Local time
Today, 10:43
Joined
Jul 26, 2013
Messages
187
Goos Afternoon,

The following piece off SQL code is used in a Query to ensure that only a single hard copy document is mailed to 2 recipients at one address where an electronic copy is not required(Hence the False statement). The need has now arisen to add an 'OR' function to cause a copy to be sent when an overriding instruction is contained in a 'Notes' field.
Adding the 'OR' function below the 'False' expression produces the following SQL code which is obviously incorrect.

SELECT a.[Member ID], a.[Address 1], a.[Member Name], a.[Address 2], a.Town, a.PostCode, a.[e-News List], a.[e-Mail List]
FROM [Mail List] AS a
GROUP BY a.[Member ID], a.[Address 1], a.[Member Name], a.[Address 2], a.Town, a.PostCode, a.[e-News List], a.[e-Mail List], CStr([a].[Member ID])+[a].[Address 1]
HAVING (((a.[e-News List])=False) AND ((CStr([a].[Member ID])+[a].[Address 1])=(Select cStr(Min(b.[Member ID])) + b.[Address 1]
From [Mail List] as b
Where b.[Address 1] = a.[Address 1]
Group By [Address 1]))) OR ((([Mail List].[Notes])="*XTRANL*"));

Any suggestion to locate the 'Or' function in the correct place would be gratefully received.

Regards,

jcbhydro
 
ELECT a.[Member ID], a.[Address 1], a.[Member Name], a.[Address 2], a.Town, a.PostCode, a.[e-News List], a.[e-Mail List]
FROM [Mail List] AS a
GROUP BY a.[Member ID], a.[Address 1], a.[Member Name], a.[Address 2], a.Town, a.PostCode, a.[e-News List], a.[e-Mail List], CStr([a].[Member ID])+[a].[Address 1]
HAVING (((a.[e-News List])=False OR (a.[Mail List].[Notes])="*XTRANL*")) AND ((CStr([a].[Member ID])+[a].[Address 1])=(Select cStr(Min(b.[Member ID])) + b.[Address 1]
From [Mail List] as b
Where b.[Address 1] = a.[Address 1]
Group By [Address 1])));
 
Hi Arnelgo,

Thanks for your suggestion.
I had tried that location for the 'OR' statement but it merely causes the Query to ignore the single Addtress feature.
Would it be more appropriate to put the 'OR' expression after the 'AND' statement in the 'HAVING' line of code.

Regards,

jcbhydro
 
I have done a few more tests with equally negative results.

If the 'OR' Statement is included at the beginning or middle of the 'HAVING' line of code the 'OR' statement has no effect whatsoever. If it is incorporated after the 'AND' statement it causes the Query to find no records at all.

What I am trying to achieve is to find all records which have a 'FALSE' attribute and select only one for each address 'EXCEPT' where the 'Notes' field includes the text XTRANL.

My limited experience of SQL has caused me utter bafflement in this case.

Regards,

jcbhydro
 

Users who are viewing this thread

Back
Top Bottom