How can I make a query return zero values when there are no results?
The first level of queries returns data from tables based on a selection made in a form and reported in a different query.
The base query, qryPrintCostAss ets, returns all data from tblAssets based on a selection in a form. qryPrintCostAss ets.ID is key to the rest of the queries pulling their data.
qryPrintCostSup port pulls from tblSupport based on qryPrintCostAss ets.ID. When there are no entries in tblSupport for a particular printer, qryPrintCostSup port returns a row of empty cells.
qryPrintCostMet er does the same as qryPrintCostSup port, except it is pulling from tblPrinterMeter for meter readings (page counts). The syntax is essentially the same except the fields are numeric except for the AssetsID field, which is exactly the same as in qryPrintCostSup port. No entries in tblPrinterMeter results in a row of empty cells.
Then there are 2 queries dependent on these two queries. qryPrintCostSup portCostTotals sums qryPrintCostSup port.Cost:
If the results of qryPrintCostSup port are a row of empty cells, the result of qryPrintCostSup portCostTotals is no cells under the column titles.
The same holds true for qryPrintCostMet erTotals, which uses the MAX value from the qryPrintCostMet er fields to find the highest value for BCount (black), CCount (color), and TCount (total). If qryPrintCostMet er is a row of empty cells, qryPrintCostMet erTotals returns no cells under the column headers.
When either qryPrintCostMet erTotals or qryPrintCostSup portCostTotals has no cells, qryPrintCostMas ter also returns no cells under the column headers/titles.
qryPrintCostMas ter uses multiple INNER JOINs to pull data from several other queries all tracing back to qryPrintCostAss ets in one way or another for the purpose of populating fields in a form to track printer costs.
What is the difference between a query returning empty/blank cells and a query returning no cells?
Is there error correction or handling that I can employ in SQL that would ultimately allow qryPrintCostMas ter to return the expected row of values simply excluding those for which there are none?
The first level of queries returns data from tables based on a selection made in a form and reported in a different query.
The base query, qryPrintCostAss ets, returns all data from tblAssets based on a selection in a form. qryPrintCostAss ets.ID is key to the rest of the queries pulling their data.
Code:
SELECT * FROM tblAssets WHERE (((tblAssets.ID)=Forms!formPrintCost!listPrinter));
Code:
SELECT qryPrintCostAssets.ID AS AssetID, Left([tblSupport.Problem],50) AS Problem, tblSupport.Date, tblSupport.DownTime, tblSupport.Cost FROM tblSupport INNER JOIN qryPrintCostAssets ON tblSupport.AssetID=qryPrintCostAssets.ID ORDER BY tblSupport.ID;
Then there are 2 queries dependent on these two queries. qryPrintCostSup portCostTotals sums qryPrintCostSup port.Cost:
Code:
SELECT qryPrintCostAssets.ID AS AssetID, Sum(qryPrintCostSupport.Cost) AS SCost FROM qryPrintCostAssets INNER JOIN qryPrintCostSupport ON qryPrintCostAssets.ID=qryPrintCostsupport.AssetID GROUP BY qryPrintCostAssets.ID;
The same holds true for qryPrintCostMet erTotals, which uses the MAX value from the qryPrintCostMet er fields to find the highest value for BCount (black), CCount (color), and TCount (total). If qryPrintCostMet er is a row of empty cells, qryPrintCostMet erTotals returns no cells under the column headers.
When either qryPrintCostMet erTotals or qryPrintCostSup portCostTotals has no cells, qryPrintCostMas ter also returns no cells under the column headers/titles.
qryPrintCostMas ter uses multiple INNER JOINs to pull data from several other queries all tracing back to qryPrintCostAss ets in one way or another for the purpose of populating fields in a form to track printer costs.
Code:
SELECT qryPrintCostAssets.ID AS AssetID, qryPrintCostAssets.UID, qryPrintCostAssets.ModelID, qryPrintCostAssets.Status, qryPrintCostAssets.Dept, qryPrintCostAssets.SubDept, qryPrintCostAssets.SN, qryPrintCostAssets.Box, qryPrintCostAssets.BoxDrop, qryPrintCostAssets.NetName, qryPrintCostAssets.MACAddress, qryPrintCostAssets.IPAddress, qryPrintCostAssets.Description, qryPrintCostAcquire.ID AS AcquireID, qryPrintCostAcquire.Method, qryPrintCostAcquire.Price, qryPrintCostAcquire.DateAcquired, qryPrintCostAcquire.Number, qryPrintCostAcquire.LeaseBegin, qryPrintCostAcquire.LeaseEnd, qryPrintCostAcquire.Vendor, qryPrintCostMeterTotals.BCount, qryPrintCostMeterTotals.CCount, qryPrintCostMeterTotals.TCount, qryPrintCostSupportCostTotals.SCost FROM ((qryPrintCostAssets INNER JOIN qryPrintCostAcquire ON qryPrintCostAssets.ID=qryPrintCostAcquire.AssetID) INNER JOIN qryPrintCostSupportCostTotals ON qryPrintCostAssets.ID=qryPrintCostSupportCostTotals.AssetID) INNER JOIN qryPrintCostMeterTotals ON qryPrintCostAssets.ID=qryPrintCostMeterTotals.AssetID;
Is there error correction or handling that I can employ in SQL that would ultimately allow qryPrintCostMas ter to return the expected row of values simply excluding those for which there are none?
Comment