Question : SQL Query, Union All Question

i have the following SQL Query and would like know why i can't add a Where Clause to it.

SELECT tblServiceAddress.SID, tblServiceAddress.ServiceStreet, 1 as Sort,  tblServiceAddress.CID FROM tblServiceAddress UNION ALL select Number, Text, 0 as Sort,  Forms!frmBid.cboCustomer  as  CID from wrk_New
ORDER BY Sort, tblServiceAddress.ServiceStreet;

I Would like to a Where like this

SELECT tblServiceAddress.SID, tblServiceAddress.ServiceStreet, 1 as Sort,  tblServiceAddress.CID FROM tblServiceAddress UNION ALL select Number, Text, 0 as Sort,  Forms!frmBid.cboCustomer  as  CID from wrk_New
Where CID = Forms!frmBid.cboCustomer
ORDER BY Sort, tblServiceAddress.ServiceStreet;

but when i do this the results won't brint in the one record i am using the union for.. which is a text field that Says "Add New" in the second column

I can save the first query as a query and then use the combobox row source as the query and run a filter, and it works but would like to have it all in statement without having the extra query.

Answer : SQL Query, Union All Question

Hi j_Bryan,

within a UNION ALL you have 2 SELECT statements ... which of the 2 did you want the WHERE clause to operate, 1st, 2nd or both?  I suspect you need:

SELECT tblServiceAddress.SID, tblServiceAddress.ServiceStreet, 1 as Sort,  tblServiceAddress.CID FROM tblServiceAddress
Where CID = Forms!frmBid.cboCustomer
UNION ALL
select Number, Text, 0 as Sort,  Forms!frmBid.cboCustomer  as  CID from wrk_New
ORDER BY Sort, tblServiceAddress.ServiceStreet;


lwadwell
Random Solutions  
 
programming4us programming4us