Passing criteria from one Excel Query to another
The following SQL code is from a query I run in excel as part of a VBA
macro I wrote. You can see that it prompts me for 2 date parameters
and a division parameter. I would like to pass these parameters to 3
subsequent queries that use the same dates and division. Currently,
the user must re-enter these parameters 4 times for the macro to
complete processing. This is very cumbersome and leaves much room for
error. How do I save the variables and pass them to each query?
SELECT CMASCP.CPCUS, CMASTR.CU_NME, CMASCP.CPDIV, CMASCP.CP_CID,
CMASCP.CPCDTE, CMASCP.CPCSMN, CMASCP.CPTYP, CMASCP.CPCDET,
CMASCP.CPSEQ
FROM S10BB89B.QS36F.CMASCP CMASCP, S10BB89B.QS36F.CMASTR CMASTR
WHERE CMASCP.CPCUS = CMASTR.CU_CUS AND CMASCP.CPDIV = CMASTR.CU_DIV
AND CMASCP.CPCO = CMASTR.CU_CO AND ((CMASCP.CPCDTE Between ? And ?)
AND (CMASCP.CPDIV=?))
Thanks for any suggestions.
|