473,406 Members | 2,705 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,406 software developers and data experts.

Returning 0 for fields with no records

I have a table called tblServices with the fields ServicesID,
ServicesType, ServicesQuantity, ServicesDate
It contains entries for services we distribute, etc.

I have another table called tblServicesLists with the fields
ServiceTypeID, ServiceType, ServiceSort

I use the tblServicesLists for combo boxes to allow users to select
from the ServiceType options. The type selected is inserted into
tblServices as ServicesType.

I would like to get a query of the quantities of each service in the
tblServicesLists table.

If I use the following query (using a date range based on a form), I
get quantities for only those services which have records in
tblServices.

SELECT tblServices.ServicesType,
Count(DCount("ServicesLink","tblServices","")) AS ServiceCount
FROM tblServicesLists INNER JOIN tblServices ON
tblServicesLists.ServiceSelect = tblServices.ServicesType
WHERE (((tblServices.ServicesDate) Between [Forms]!
[frm_Statistics_Range]![txtStartDate] And [Forms]!
[frm_Statistics_Range]![txtEndDate]))
GROUP BY tblServices.ServicesType;

However, what I want is totals for all service types, with a 0 for all
types that have no records in tblServices.

Thanks!
Jul 14 '08 #1
6 1182
RussCRM wrote:
I have a table called tblServices with the fields ServicesID,
ServicesType, ServicesQuantity, ServicesDate
It contains entries for services we distribute, etc.

I have another table called tblServicesLists with the fields
ServiceTypeID, ServiceType, ServiceSort

I use the tblServicesLists for combo boxes to allow users to select
from the ServiceType options. The type selected is inserted into
tblServices as ServicesType.

I would like to get a query of the quantities of each service in the
tblServicesLists table.

If I use the following query (using a date range based on a form), I
get quantities for only those services which have records in
tblServices.

SELECT tblServices.ServicesType,
Count(DCount("ServicesLink","tblServices","")) AS ServiceCount
FROM tblServicesLists INNER JOIN tblServices ON
tblServicesLists.ServiceSelect = tblServices.ServicesType
WHERE (((tblServices.ServicesDate) Between [Forms]!
[frm_Statistics_Range]![txtStartDate] And [Forms]!
[frm_Statistics_Range]![txtEndDate]))
GROUP BY tblServices.ServicesType;

However, what I want is totals for all service types, with a 0 for all
types that have no records in tblServices.

Thanks!
Change the word Inner to Left.
Jul 14 '08 #2
Didn't work :(
Jul 14 '08 #3
Salad wrote:
RussCRM wrote:
>I have a table called tblServices with the fields ServicesID,
ServicesType, ServicesQuantity, ServicesDate
It contains entries for services we distribute, etc.

I have another table called tblServicesLists with the fields
ServiceTypeID, ServiceType, ServiceSort

I use the tblServicesLists for combo boxes to allow users to select
from the ServiceType options. The type selected is inserted into
tblServices as ServicesType.

I would like to get a query of the quantities of each service in the
tblServicesLists table.

If I use the following query (using a date range based on a form), I
get quantities for only those services which have records in
tblServices.

SELECT tblServices.ServicesType,
Count(DCount("ServicesLink","tblServices","")) AS ServiceCount
FROM tblServicesLists INNER JOIN tblServices ON
tblServicesLists.ServiceSelect = tblServices.ServicesType
WHERE (((tblServices.ServicesDate) Between [Forms]!
[frm_Statistics_Range]![txtStartDate] And [Forms]!
[frm_Statistics_Range]![txtEndDate]))
GROUP BY tblServices.ServicesType;

However, what I want is totals for all service types, with a 0 for all
types that have no records in tblServices.

Thanks!


Change the word Inner to Left.
Not sure what Count(DCount()) does.

Try this. Open up your query in design mode. Dbl-Click on the line and
change it to All in ServicesList and Matching in ServicesType. I might
have your table names messed up, adjust as required.

Create a calculated column called ServicesCount in the query
ServicesCount : IIF(Not IsNull(ServicesType!ServicesSelect,1,0)
Now in the Totals band use Sum to get the ServicesCount.
Jul 14 '08 #4
Here's what I came up with. Seems to work:

SELECT tblServicesLists.ServiceSelect, Sum(IIf(Not
IsNull([tblServices]![ServicesType]),1,0)) AS ServicesCount
FROM tblServicesLists LEFT JOIN tblServices ON
tblServicesLists.ServiceSelect = tblServices.ServicesType
GROUP BY tblServicesLists.ServiceSelect;
Jul 14 '08 #5
Except when I limit the date range...

Jul 14 '08 #6
I used another query to filter by date and then used that query in
place of my tblServices. Seems to work.
Jul 14 '08 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Jeff North | last post by:
I'm stumped and my brains are fried!!!! I have the following data +-------+------------------------------+------------+ | resID | FLEName | VersionNbr |...
2
by: Shaiguy | last post by:
I have a table containing the following fields: ProjectUpdateID (PrimaryKey) ProjectID UpdateDate I would like to create a Query in Ms Access 2000 which will return me the most recent 2...
2
by: Simon Pleasants | last post by:
Am something of a newbie at this, so please bear with any stupid questions. I have created a database to track shipments that we import. The information is stored in a table and I have created...
4
by: JeremiahOSullivan | last post by:
Hi, I have a sql server database with 1.7 million records in a table, with about 30 fields When I run select * from tablename it can take over 5 minutes. How can I get this time down or is...
1
by: Jeff Silverman | last post by:
I have a PHP program that almost works. I'm running it from the command line and simulating a form using a GET method. That part is working, but I get spurious records with all of the fields...
11
by: klove1209 | last post by:
Good afternoon, Can someone please guide me towards how to return records from a table. I currently have a table with about 21 fields, and 21 records. I have one field that is just text and the...
1
by: vinodkus | last post by:
I M BEGINNER IN ASP I WANT TO RETURN TOTAL RECORDS FROM A TABLE. THERE ARE TWO FORMS CLASS1.ASP AND CLASS2.ASP THROUGH FIRST FORM I JUST POST THE NAME OF TABLE SO I M WRITING THE CODE OF...
13
by: Karl Groves | last post by:
I'm missing something very obvious, but it is getting late and I've stared at it too long. TIA for responses I am writing a basic function (listed at the bottom of this post) that returns...
3
rsmccli
by: rsmccli | last post by:
Access 2002 Hi. I have a command button that will "approve" all records currently being looked at by an "approver". For some reason, even though there are multiple records that exist in the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.