Passing parameters to UNION query

texas1992

Registered User.
Local time
Today, 12:47
Joined
May 8, 2012
Messages
25
I have a UNION query that I pass two parameters to but those two parameters are used in both sides of the union.

SELECT bill.TripDate AS Bill_TripDate, bill.voucher_nbr AS Bill_Voucher, bill.fare AS Bill_Fare, tbl_from_xl.TripDate AS XL_TripDate, tbl_from_xl.voucher_nbr AS XL_Voucher, tbl_from_xl.fare AS XL_Fare
FROM tbl_from_bill AS bill LEFT JOIN tbl_from_xl ON bill.voucher_nbr = tbl_from_xl.voucher_nbr
Where bill.TripDate BETWEEN FromDate AND ToDate
ORDER BY bill.voucher_nbr

UNION

SELECT bill.TripDate AS Bill_TripDate, bill.voucher_nbr AS Bill_Voucher, bill.fare AS Bill_Fare, tbl_from_xl.TripDate AS XL_TripDate, tbl_from_xl.voucher_nbr AS XL_Voucher, tbl_from_xl.fare AS XL_Fare
FROM tbl_from_bill AS bill RIGHT JOIN tbl_from_xl ON bill.voucher_nbr=tbl_from_xl.voucher_nbr
WHERE tbl_from_xl.TripDate BETWEEN FromDate AND ToDate OR tbl_from_xl.BillingMonth BETWEEN FromDate AND ToDate;


As you can see, I am using FromDate and ToDate but on two separate tables.

My question is can I get this to only prompt me for the parameters once rather than prompting me 4 times each time I run the query?

Thanks.
 
I would enter the values on a form and have the queries look there for them. You have a lot more control that way anyway.
 
I put a form in front of the query and that helped. Thanks.
 

Users who are viewing this thread

Back
Top Bottom