You would see if you didn't assume what the other person was
trying to do. You're the person who makes assumptions about what
others are trying to do, without really knowing. I wouldn't be
asking the question if the first query wasn't needed. I'd love to
see your simplified, "don't need two-queries" version, that can run
any of these hundreds of single locations, 25 region/sub-region
combos, and "areas", all with a simple user-front end. All the user
has to do on the form is select a location, region or area, and
month/year. The 2 queries do all the work.
The user can select a single location, a region, or an area,
over 25 combos from the report's main form. The beauty o the query
is that, regardless whether the user wants a single location
report, one of dozens of region or sub-region reports, or another
sub-set type of region (area), the first query always selects the
correct locations for the main (2nd) query to run it's totals and
calculations on.
Here's a copy of the first query, with some item's "XXX"d"
out for confidentiality. When the query runs, everything you need
is all wrapped up in a nice little list called
GetLocations.location. Allowing the main query to run any of 150
single locations, 25 regions, sub-regions, and other area-types
(frequently changing).
<CFIF '#url.RepType#' EQ 'location'>
<CFSET location = '#url.location#'>
<!---- CREATE A LIST OF locationS, FOR A SINGLE location,
TO BE USED IN QUERIES ----->
<CFQUERY name="Getlocations" datasource="MyDBSQL">
SELECT xxx as location
FROM location_Region_Table
WHERE xxx = '#location#'
ORDER BY location
</CFQUERY>
<CFELSEIF '#url.RepType#' EQ 'region'>
<CFSET location = '#url.location#'>
<!------ CREATE A LIST OF locationS, WHEN A REGION IS
SELECTED, TO BE USED IN QUERIES ----->
<CFIF #location# IS "NORTH AMERICA">
<CFQUERY name="Getlocations" datasource="MyDBSQL">
SELECT xxx as location
FROM location_Region_Table
WHERE region = 'xxxxxxx OPERATIONS' or
region = 'XXX' or
region = 'XXX'
ORDER BY location
</CFQUERY>
<CFELSEIF #location# IS "INTERNATIONAL">
<CFQUERY name="Getlocations" datasource="MyDBSQL">
SELECT xxx as location
FROM location_Region_Table
WHERE region = 'ATLANTIC' or
region = 'PACIFIC'
ORDER BY location
</CFQUERY>
<CFELSEIF #location# IS "EAST">
<CFQUERY name="Getlocations" datasource="MyDBSQL">
SELECT xxx as location
FROM location_Region_Table
WHERE subregion IN('EAST LINE','CARIBBEAN')
ORDER BY location
</CFQUERY>
<CFELSEIF #location# IS "WEST">
<CFQUERY name="Getlocations" datasource="MyDBSQL">
SELECT xxx as location
FROM location_Region_Table
WHERE subregion IN('WEST LINE','MEXICO','SOUTH AMERICA')
ORDER BY location
</CFQUERY>
<CFELSEIF #location# IS "XX MG DIR">
<CFQUERY name="Getlocations" datasource="MyDBSQL">
SELECT xxx as location
FROM location_Region_Table
WHERE subregion IN('XXX METRO','XXX METRO','XXX METRO','XXX
METRO')
ORDER BY location
</CFQUERY>
<CFELSEIF #location# IS "XXXXXXXX">
<CFQUERY name="Getlocations" datasource="MyDBSQL">
SELECT xxx as location
FROM location_Region_Table
WHERE xxx IN('AAA','BBB','CCC','DDD','EEE','FFF')
ORDER BY location
</CFQUERY>
<CFELSEIF #location# IS "SYSTEM">
<CFQUERY name="Getlocations" datasource="MyDBSQL">
SELECT xxx as location
FROM location_Region_Table
WHERE division IN('NORTH AMERICA','INTERNATIONAL')
ORDER BY location
</CFQUERY>
<CFELSEIF (#location# IS "xxxxxxx OPERATIONS") OR
(#location# IS "XXXX")>
<CFQUERY name="Getlocations" datasource="MyDBSQL">
SELECT xxx as location
FROM location_Region_Table
WHERE region = '#location#'
ORDER BY location
</CFQUERY>
<CFELSE>
<CFQUERY name="Getlocations" datasource="MyDBSQL">
SELECT xxx as location
FROM location_Region_Table
WHERE subregion = '#location#'
ORDER BY location
</CFQUERY>
</CFIF>
<CFELSE>
<CFSET location = Mid(url.location,1,3)>
<!---- CREATE A LIST OF locationS, FOR A SINGLE
location/GATEWAY,
TO BE USED IN QUERIES WHEN A GATEWAY location IS SELECTED
----->
<CFQUERY name="Getlocations" datasource="MyDBSQL">
SELECT xxx as location
FROM location_Region_Table
WHERE xxx = SUBSTRING('#location#',1,3)
ORDER BY location
</CFQUERY>
</CFIF>