DougAtAvalon
Programmer
Does any one now how to do a union select with a where clause coming from 2 fields.
For example:
Select Field 1... From AAA; Union Select Field 2... From AAA
Now the Where clause is giving me a problem. This is it in plane terms. I want the record to show up if it has "xxx" in field1 or field2 along with some other where criteria
-----------
THIS IS THE ORIGINAL THAT WORKS(please note Loc1 and Loc2 is what changes in the where clauses):
SELECT Providers.ProviderID, IIf(Not IsNull([Company]),[Company],[LastName] & ', ' & [FirstName] & ' ' & [MiddleName]) AS Provider, Providers.CountyLoc1, ProviderServices.ServiceID, Providers.PostalCodeLoc1
FROM Providers INNER JOIN ProviderServices ON Providers.ProviderID = ProviderServices.ProviderID
WHERE (((Providers.CountyLoc1)="Bergen" AND ((ProviderServices.ServiceID)=45) AND ((Providers.PostalCodeLoc1)="07834")
ORDER BY IIf(Not IsNull([Company]),[Company],[LastName] & ', ' & [FirstName] & ' ' & [MiddleName]);
------------------------------------------------
THIS IS THE UNION SELECT WITH THE 2 WHERE CLAUSES (please note Loc1 and Loc2 is what changes in the where clauses):
SELECT Providers.ProviderID, IIf(Not IsNull([Company]),[Company],[LastName] & ', ' & [FirstName] & ' ' & [MiddleName]) AS Provider, Providers.CountyLoc1, ProviderServices.ServiceID, Providers.PostalCodeLoc1 FROM Providers INNER JOIN ProviderServices ON Providers.ProviderID = ProviderServices.ProviderID WHERE (((Providers.CountyLoc1)="Bergen" AND ((ProviderServices.ServiceID)=45) AND ((Providers.PostalCodeLoc1)="07834"); UNION SELECT Providers.ProviderID, IIf(Not IsNull([Company]),[Company],[LastName] & ', ' & [FirstName] & ' ' & [MiddleName]) AS Provider, Providers.CountyLoc1, ProviderServices.ServiceID, Providers.PostalCodeLoc1 FROM Providers INNER JOIN ProviderServices ON Providers.ProviderID = ProviderServices.ProviderID WHERE (((Providers.CountyLoc2)="Bergen" AND ((ProviderServices.ServiceID)=45) AND ((Providers.PostalCodeLoc2)="07834")
ORDER BY IIf(Not IsNull([Company]),[Company],[LastName] & ', ' & [FirstName] & ' ' & [MiddleName]);
-----------------------------------------
-Doug
For example:
Select Field 1... From AAA; Union Select Field 2... From AAA
Now the Where clause is giving me a problem. This is it in plane terms. I want the record to show up if it has "xxx" in field1 or field2 along with some other where criteria
-----------
THIS IS THE ORIGINAL THAT WORKS(please note Loc1 and Loc2 is what changes in the where clauses):
SELECT Providers.ProviderID, IIf(Not IsNull([Company]),[Company],[LastName] & ', ' & [FirstName] & ' ' & [MiddleName]) AS Provider, Providers.CountyLoc1, ProviderServices.ServiceID, Providers.PostalCodeLoc1
FROM Providers INNER JOIN ProviderServices ON Providers.ProviderID = ProviderServices.ProviderID
WHERE (((Providers.CountyLoc1)="Bergen" AND ((ProviderServices.ServiceID)=45) AND ((Providers.PostalCodeLoc1)="07834")
ORDER BY IIf(Not IsNull([Company]),[Company],[LastName] & ', ' & [FirstName] & ' ' & [MiddleName]);
------------------------------------------------
THIS IS THE UNION SELECT WITH THE 2 WHERE CLAUSES (please note Loc1 and Loc2 is what changes in the where clauses):
SELECT Providers.ProviderID, IIf(Not IsNull([Company]),[Company],[LastName] & ', ' & [FirstName] & ' ' & [MiddleName]) AS Provider, Providers.CountyLoc1, ProviderServices.ServiceID, Providers.PostalCodeLoc1 FROM Providers INNER JOIN ProviderServices ON Providers.ProviderID = ProviderServices.ProviderID WHERE (((Providers.CountyLoc1)="Bergen" AND ((ProviderServices.ServiceID)=45) AND ((Providers.PostalCodeLoc1)="07834"); UNION SELECT Providers.ProviderID, IIf(Not IsNull([Company]),[Company],[LastName] & ', ' & [FirstName] & ' ' & [MiddleName]) AS Provider, Providers.CountyLoc1, ProviderServices.ServiceID, Providers.PostalCodeLoc1 FROM Providers INNER JOIN ProviderServices ON Providers.ProviderID = ProviderServices.ProviderID WHERE (((Providers.CountyLoc2)="Bergen" AND ((ProviderServices.ServiceID)=45) AND ((Providers.PostalCodeLoc2)="07834")
ORDER BY IIf(Not IsNull([Company]),[Company],[LastName] & ', ' & [FirstName] & ' ' & [MiddleName]);
-----------------------------------------
-Doug