G
Guest
Hi all,
I've got three queries that work together to combine the results of two
tables. I've got two queries which sum the values (grouped as required) I
need from two tables. I then use a final query to pair the values up, using
a join.
However, the query is dynamic, as it's based on search criteria specified by
the user. So what I'd really like to is create one big query which will
still create the result I need without me having to rewrite the existing
queries, every time the user changes the search criteria.
The following is the queries. I removed the user specific aspects of the
SQL statement as I can add and remove these easily myself (just
adding/removing qualifiers from the where statement). The 'guts' of the
queries are below. Optimally, I'd like to pass the query as a String to
another form and use that String as the RecordSource. Getting the String
back and forth I can do, I'm just having issues creating one query from my
three existing queries.
-----------------------------------------------
QUERY 1: temp_getTotalTestedQuantity
-----------------------------------------------
SELECT tblDetail.DTL_ITEM_NUM, tblDetail.DTL_AREA_NUM,
Sum(tblDetail.DTL_QUAN) AS ItemsReviewed
FROM tblDetail
GROUP BY tblDetail.DTL_ITEM_NUM, tblDetail.DTL_AREA_NUM;
----------------------------------------------
QUERY 2: temp_getTotalDefectQuantity
----------------------------------------------
SELECT tblDefectCount.DC_ITEM_NUM, tblDefectCount.DC_AREA_NUM,
Sum(tblDefectCount.DC_DF_QUAN) AS DefectsSum
FROM tblDefectCount
GROUP BY tblDefectCount.DC_ITEM_NUM, tblDefectCount.DC_AREA_NUM;
-----------------------------------------
QUERY 3: temp_getTotalQuantities
-----------------------------------------
SELECT DISTINCT temp_getTotalTestedQuantity.DTL_ITEM_NUM,
temp_getTotalTestedQuantity.DTL_AREA_NUM,
temp_getTotalTestedQuantity.ItemsReviewed,
temp_getTotalDefectQuantity.DefectsSum
FROM temp_getTotalTestedQuantity
LEFT JOIN temp_getTotalDefectQuantity ON
(temp_getTotalTestedQuantity.DTL_AREA_NUM =
temp_getTotalDefectQuantity.DC_AREA_NUM) AND
(temp_getTotalTestedQuantity.DTL_ITEM_NUM =
temp_getTotalDefectQuantity.DC_ITEM_NUM);
If anyone has any suggestions, or if you have to tell me I can't do what I
want, I'd appreciate it.
Thanks,
Jay
I've got three queries that work together to combine the results of two
tables. I've got two queries which sum the values (grouped as required) I
need from two tables. I then use a final query to pair the values up, using
a join.
However, the query is dynamic, as it's based on search criteria specified by
the user. So what I'd really like to is create one big query which will
still create the result I need without me having to rewrite the existing
queries, every time the user changes the search criteria.
The following is the queries. I removed the user specific aspects of the
SQL statement as I can add and remove these easily myself (just
adding/removing qualifiers from the where statement). The 'guts' of the
queries are below. Optimally, I'd like to pass the query as a String to
another form and use that String as the RecordSource. Getting the String
back and forth I can do, I'm just having issues creating one query from my
three existing queries.
-----------------------------------------------
QUERY 1: temp_getTotalTestedQuantity
-----------------------------------------------
SELECT tblDetail.DTL_ITEM_NUM, tblDetail.DTL_AREA_NUM,
Sum(tblDetail.DTL_QUAN) AS ItemsReviewed
FROM tblDetail
GROUP BY tblDetail.DTL_ITEM_NUM, tblDetail.DTL_AREA_NUM;
----------------------------------------------
QUERY 2: temp_getTotalDefectQuantity
----------------------------------------------
SELECT tblDefectCount.DC_ITEM_NUM, tblDefectCount.DC_AREA_NUM,
Sum(tblDefectCount.DC_DF_QUAN) AS DefectsSum
FROM tblDefectCount
GROUP BY tblDefectCount.DC_ITEM_NUM, tblDefectCount.DC_AREA_NUM;
-----------------------------------------
QUERY 3: temp_getTotalQuantities
-----------------------------------------
SELECT DISTINCT temp_getTotalTestedQuantity.DTL_ITEM_NUM,
temp_getTotalTestedQuantity.DTL_AREA_NUM,
temp_getTotalTestedQuantity.ItemsReviewed,
temp_getTotalDefectQuantity.DefectsSum
FROM temp_getTotalTestedQuantity
LEFT JOIN temp_getTotalDefectQuantity ON
(temp_getTotalTestedQuantity.DTL_AREA_NUM =
temp_getTotalDefectQuantity.DC_AREA_NUM) AND
(temp_getTotalTestedQuantity.DTL_ITEM_NUM =
temp_getTotalDefectQuantity.DC_ITEM_NUM);
If anyone has any suggestions, or if you have to tell me I can't do what I
want, I'd appreciate it.
Thanks,
Jay