473,378 Members | 1,162 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

SQL query no results

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, qryPrintCostAssets, returns all data from tblAssets based on a selection in a form. qryPrintCostAssets.ID is key to the rest of the queries pulling their data.

Expand|Select|Wrap|Line Numbers
  1. SELECT *
  2. FROM tblAssets
  3. WHERE (((tblAssets.ID)=Forms!formPrintCost!listPrinter));
  4.  
qryPrintCostSupport pulls from tblSupport based on qryPrintCostAssets.ID. When there are no entries in tblSupport for a particular printer, qryPrintCostSupport returns a row of empty cells.

Expand|Select|Wrap|Line Numbers
  1. SELECT qryPrintCostAssets.ID AS AssetID, Left([tblSupport.Problem],50) AS Problem, tblSupport.Date, tblSupport.DownTime, tblSupport.Cost
  2. FROM tblSupport INNER JOIN qryPrintCostAssets ON tblSupport.AssetID=qryPrintCostAssets.ID
  3. ORDER BY tblSupport.ID;
  4.  
qryPrintCostMeter does the same as qryPrintCostSupport, 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 qryPrintCostSupport. No entries in tblPrinterMeter results in a row of empty cells.

Then there are 2 queries dependent on these two queries. qryPrintCostSupportCostTotals sums qryPrintCostSupport.Cost:

Expand|Select|Wrap|Line Numbers
  1. SELECT qryPrintCostAssets.ID AS AssetID, Sum(qryPrintCostSupport.Cost) AS SCost
  2. FROM qryPrintCostAssets INNER JOIN qryPrintCostSupport ON qryPrintCostAssets.ID=qryPrintCostsupport.AssetID
  3. GROUP BY qryPrintCostAssets.ID;
  4.  
If the results of qryPrintCostSupport are a row of empty cells, the result of qryPrintCostSupportCostTotals is no cells under the column titles.

The same holds true for qryPrintCostMeterTotals, which uses the MAX value from the qryPrintCostMeter fields to find the highest value for BCount (black), CCount (color), and TCount (total). If qryPrintCostMeter is a row of empty cells, qryPrintCostMeterTotals returns no cells under the column headers.

When either qryPrintCostMeterTotals or qryPrintCostSupportCostTotals has no cells, qryPrintCostMaster also returns no cells under the column headers/titles.

qryPrintCostMaster uses multiple INNER JOINs to pull data from several other queries all tracing back to qryPrintCostAssets in one way or another for the purpose of populating fields in a form to track printer costs.

Expand|Select|Wrap|Line Numbers
  1. 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
  2. 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;
  3.  
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 qryPrintCostMaster to return the expected row of values simply excluding those for which there are none?
Aug 31 '10 #1

✓ answered by Oralloy

You might want to try using an outer join, rather than an inner join.

Just because you see a blank row in the output display doesn't mean that there is actually anything there.

4 2237
Oralloy
985 Expert 512MB
You might want to try using an outer join, rather than an inner join.

Just because you see a blank row in the output display doesn't mean that there is actually anything there.
Aug 31 '10 #2
Is the syntax the same for INNER and OUTER joins?

What are the substantive differences between the two?

What are examples of times one and the other are appropriate?
Aug 31 '10 #3
Ok, figured this out with the pointers you gave, Oralloy. Thank you.

I want to be able to do more things with the two queries qryPrintCostSupport and qryPrintCostMeter, so the fix had to work by that point in the query ladder.

So I changed the INNER JOINs in those two queries to RIGHT JOINs (which Access trimmed down from RIGHT OUTER JOINs that I'd typed). When there is no data in either tblSupport or tblPrinterMeter for a selected printer, they return a single record with only the AssetID populated.

This gets handed down to qryPrintCostMeterTotals and qryPrintCostSupportCostTotals which, because it's an actual record and not a blank return, show the same record with only the AssetID populated. And the qryPrintCostMaster shows all available information for the selected printer as a single record without erroring when data is not available in one or both of those fields.

Thank you for the help.
Aug 31 '10 #4
Oralloy
985 Expert 512MB
Glad to help.

Good luck with your project.

Oralloy
Aug 31 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Guy Erez | last post by:
Hi, I'm running queries with MySql 4.0.17 that return thousands of records. Because I need to present them in GUI, I returieve the results in chunks using LIMIT, for example - get first 100,...
6
by: Brian | last post by:
Hello, Basically, I'm running a query on a form's activation, and I'd like to have the results of the query be placed into other fields on the same form automatically. Does anybody know how...
0
by: Rob | last post by:
I doubt this is the best way to do it, but what I came up with was to hide the XML in an HTML Comment then edit the file deleting the HTML stuff and keep the XML results. If anyone has a better...
1
by: ljungers | last post by:
Hi and I hope that someone may have an answer for this, or an example of what I need to do. I have a Access database that a clerk will be entering a Order Number or Client Name or a Client City in a...
7
by: fcolon75 | last post by:
I'm an experienced Access user, but very new to coding VBA in Access. I'd like to do the following: 1) Develop a basic query in the query designer. 2) Call that query from a VBA script 3)...
9
by: Kelii | last post by:
I've been trying to get this piece to work for a few hours, but have given up. I hope someone out there can help, I think the issue is relatively straightforward, but being a novice, I'm stumped....
2
by: Himmel | last post by:
Hello! The reference database I currently use runs queries that pull data from hundreds of tables in order to create user-friendly form view. The problem is that these queries can take upwards of...
1
by: aaronkm | last post by:
Hello thescripts and well met. I've recently been handed a new duty and have the joy of 'crash coursing' MS Access. Things are working well but I've ran into a problem that I can't seem to find...
1
by: igor221189 | last post by:
Hello everyone. I have Access 2000 database which holds student records in the school.It stores subject grades for each student.In the 'Student Grade Form', I would like to search student surname...
1
by: Arli | last post by:
I have the following linked tables: tblMainPL is my main table that I need to pull the information in from. It has the following fields: Autonumber1 -PK set as autonumber Date - short date...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.