473,396 Members | 1,921 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,396 software developers and data experts.

Having Zeros Appear

I am running a query that calculates student enrolment per course. The
problem is, if the enrolment is zero, the entire row will not be
displayed.

I tried a variety of solutions, neither of which work:

IIf(IsNull([STUDENTLIST].[ENROLMENT])," ", [STUDENTLIST].[ENROLMENT])

IIf(IsNull([STUDENTLIST].[ENROLMENT]),"0", [STUDENTLIST].[ENROLMENT])

IIf([STUDENTLIST].[ENROLMENT]="0"),"0", [STUDENTLIST].[ENROLMENT])

Wondering if anyone knows how to solve this. I'm using Access 2002
with linked tables.
Marcus
******

Nov 13 '05 #1
13 1260
Marcus,
Try Nz(([STUDENTLIST].[ENROLMENT],0). Nz is a rather useful function which
will substitute a value (any value, actually) for a null.
--
Alan Webb
kn*******@SPAMhotmail.com
"It's not IT, it's IS"

"Marcus" <to*******@yahoo.ca> wrote in message
news:11*********************@g14g2000cwa.googlegro ups.com...
I am running a query that calculates student enrolment per course. The
problem is, if the enrolment is zero, the entire row will not be
displayed.

I tried a variety of solutions, neither of which work:

IIf(IsNull([STUDENTLIST].[ENROLMENT])," ", [STUDENTLIST].[ENROLMENT])

IIf(IsNull([STUDENTLIST].[ENROLMENT]),"0", [STUDENTLIST].[ENROLMENT])

IIf([STUDENTLIST].[ENROLMENT]="0"),"0", [STUDENTLIST].[ENROLMENT])

Wondering if anyone knows how to solve this. I'm using Access 2002
with linked tables.
Marcus
******

Nov 13 '05 #2
Please post your query. Without looking at your query, I guess you
should use "left join":

select CourseName, Count(*) As StudendCount from Course as c left join
StudentList s on c.CourseId = s.CourseId Group By CourseName
"Marcus" <to*******@yahoo.ca> wrote in message news:<11*********************@g14g2000cwa.googlegr oups.com>...
I am running a query that calculates student enrolment per course. The
problem is, if the enrolment is zero, the entire row will not be
displayed.

I tried a variety of solutions, neither of which work:

IIf(IsNull([STUDENTLIST].[ENROLMENT])," ", [STUDENTLIST].[ENROLMENT])

IIf(IsNull([STUDENTLIST].[ENROLMENT]),"0", [STUDENTLIST].[ENROLMENT])

IIf([STUDENTLIST].[ENROLMENT]="0"),"0", [STUDENTLIST].[ENROLMENT])

Wondering if anyone knows how to solve this. I'm using Access 2002
with linked tables.
Marcus
******

Nov 13 '05 #3
The code is as follows:

SELECT Count(SRS_CSECTION_STUDENTLIST_ASSOC.ENROLLMENT_LI ST_ID) AS
Enrol, SRS_COURSE.CODE, SRS_SECTION.CODE
FROM (SRS_STUDENT_LIST_ITEM INNER JOIN
SRS_CSECTION_STUDENTLIST_ASSOC
ON SRS_STUDENT_LIST_ITEM.STUDENT_LIST_ID =
SRS_CSECTION_STUDENTLIST_ASSOC.ENROLLMENT_LIST_ID) INNER JOIN
(SRS_SECTION INNER JOIN SRS_COURSE ON SRS_SECTION.COURSE_ID =
SRS_COURSE.COURSE_ID) ON
SRS_CSECTION_STUDENTLIST_ASSOC.COURSE_SECTION_ID =
SRS_SECTION.SECTION_ID
GROUP BY SRS_COURSE.CODE, SRS_SECTION.CODE;

Marcus
*********

Nov 13 '05 #4
"Marcus" <to*******@yahoo.ca> wrote in
news:11**********************@o13g2000cwo.googlegr oups.com:
The code is as follows:

SELECT
Count(SRS_CSECTION_STUDENTLIST_ASSOC.ENROLLMENT_LI ST_ID) AS
Enrol, SRS_COURSE.CODE, SRS_SECTION.CODE
FROM (SRS_STUDENT_LIST_ITEM INNER JOIN
SRS_CSECTION_STUDENTLIST_ASSOC
ON SRS_STUDENT_LIST_ITEM.STUDENT_LIST_ID =
SRS_CSECTION_STUDENTLIST_ASSOC.ENROLLMENT_LIST_ID) INNER JOIN
(SRS_SECTION INNER JOIN SRS_COURSE ON SRS_SECTION.COURSE_ID =
SRS_COURSE.COURSE_ID) ON
SRS_CSECTION_STUDENTLIST_ASSOC.COURSE_SECTION_ID =
SRS_SECTION.SECTION_ID
GROUP BY SRS_COURSE.CODE, SRS_SECTION.CODE;

Marcus
*********

SELECT
Count(SRS_CSECTION_STUDENTLIST_ASSOC.ENROLLMENT_LI ST_ID)
AS Enrol,
SRS_COURSE.CODE,
SRS_SECTION.CODE
FROM (SRS_STUDENT_LIST_ITEM
right JOIN
SRS_CSECTION_STUDENTLIST_ASSOC
ON SRS_STUDENT_LIST_ITEM.STUDENT_LIST_ID =
SRS_CSECTION_STUDENTLIST_ASSOC.ENROLLMENT_LIST_ID)
right JOIN
(SRS_SECTION
INNER JOIN
SRS_COURSE
ON SRS_SECTION.COURSE_ID = SRS_COURSE.COURSE_ID)
ON SRS_CSECTION_STUDENTLIST_ASSOC.COURSE_SECTION_ID =
SRS_SECTION.SECTION_ID
GROUP BY
SRS_COURSE.CODE,
SRS_SECTION.CODE;

the right joins should fix it. You may also need to change the
remaining inner join to a left join, as some versions of Access
may mis-interpret.

From the query design mode, double-click the join lines to change
the join type from the popup menu. Right joins are type 3.

--
Bob Quintal

PA is y I've altered my email address.
Nov 13 '05 #5
I created a right join and the query worked. Many thanks.

However, I have noticed a small issue. It seems that the following
column

Count(SRS_CSECTION_STUDENTLIST*_ASSOC.ENROLLMENT_L IST_ID)AS Enrol

is counting a zero enrolment as 1. I found this odd. I assume this
means that only rows are being counted, and not the actualEssentially
the "Enrol" column provides the correct count, but if there are no
students in a class the column prints "1" instead of "0".

There is no way of me being able to distinguish between a class
enrolment of "1" with a class enrolment of "0".

Is there a way I can stop thsi from happening?

I have tried

Enrol: Count(Nz(SRS_CSECTION_STUDENTLIST_ASSOC.ENROLLMENT _LIST_ID,0))

but this doesn't solve the problem.
Marcus
*********

Nov 13 '05 #6
I created a right join and the query worked. Many thanks.

However, I have noticed a small issue. It seems that the following
column

Count(SRS_CSECTION_STUDENTLIST*_ASSOC.ENROLLMENT_L IST_ID)AS Enrol

is counting a zero enrolment as 1. I found this odd. I assume this
means that only rows are being counted, and not the actualEssentially
the "Enrol" column provides the correct count, but if there are no
students in a class the column prints "1" instead of "0".

There is no way of me being able to distinguish between a class
enrolment of "1" with a class enrolment of "0".

Is there a way I can stop this from happening?

I have tried

Enrol: Count(Nz(SRS_CSECTION_STUDENTLIST_ASSOC.ENROLLMENT _LIST_ID,0))

but this doesn't solve the problem.

Nov 13 '05 #7
I created a right join and the query worked. Many thanks.

However, I have noticed a small issue. It seems that the following
column

Count(SRS_CSECTION_STUDENTLIST**_ASSOC.ENROLLMENT_ LIST_ID)AS Enrol

is counting a zero enrolment as 1. I found this odd. I assume this
means that only rows are being counted, and not the actual enrolment
field. Essentially the "Enrol" column provides the correct count, but
if there are no
students in a class the column prints "1" instead of "0".

There is no way of me being able to distinguish between a class
enrolment of "1" with a class enrolment of "0".

Is there a way I can stop this from happening?

I have tried

Enrol:
Count(Nz(SRS_CSECTION_STUDENTL*IST_ASSOC.ENROLLMEN T_LIST_ID,0*))

but this doesn't solve the problem.

Marcus
********

Nov 13 '05 #8
I created a right join and the query worked. Many thanks.

However, I have noticed a small issue. It seems that the following
column

Count(SRS_CSECTION_STUDENTLIST*_ASSOC.ENROLLMENT_L IST_ID)AS Enrol

is counting a zero enrolment as 1. I found this odd. I assume this
means that only rows are being counted, and not the actual enrolment
field. Essentially the "Enrol" column provides the correct count, but
if there are no
students in a class the column prints "1" instead of "0".

There is no way of me being able to distinguish between a class
enrolment of "1" or a class enrolment of "0".

Is there a way I can stop this from happening?

I have tried

Enrol: Count(Nz(SRS_CSECTION_STUDENTLIST_ASSOC.ENROLLMENT _LIST_ID,0))

but this doesn't solve the problem.
Marcus
******

Nov 13 '05 #9
To avoid confusion it is helpful to know that a right join is
equivalent to a left join with the tables/sources reversed. E.g.,
table1 with a type 3 right join to table2 is equivalent to table2 with
a type 2 left join to table1. So Bob's query has an equivalent query
that uses left joins instead of right joins. There's nothing
mysterious about the right joins.

James A. Fortune

Nov 13 '05 #10
You are correct about the rows being counted. If ENROLLMENT_LIST_ID is
always a 1 or a 0 you can use Sum() instead of Count(). Include Nz()
if null values are possible. Use Val(Nz()) if the 1's and 0's are text
and null values are possible. If ENROLLMENT_LIST_ID can be greater
than one, forcing you to use Count() then do something like
Sum(Abs(Nz(ENROLLMENT_LIST_ID) > 0)) AS Enrol or
Sum(Abs(Val(Nz(ENROLLMENT_LIST_ID)) > 0)) AS Enrol if text.

James A. Fortune

Nov 13 '05 #11
ENROLLMENT_LIST_ID is not always 1 or 0. ENROLLMENT_LIST_ID is a
number that is assigned to a student when they register for a course.
So, ENROLLMENT_LIST_ID could be 914131, or 56787 etc.

Essentially, I use Count(ENROLLMENT_LIST_ID) to determine how many
students are in a course. Really what I need to do is

IIf(Count(ENROLLMENT_LIST_ID) = 1, 1, 0)

but this is not accepted in MS Access, as I get an error when I run it.
The error says that "Count" is not allowed in this circumstance.

To determine whether a Count(ENROLLMENT_LIST_ID) is "1" (one student
registered in the course) or "0" (no students registered in the
course), I should really be determining whether any studentIDs are
associated with Count(ENROLLMENT_LIST_ID). For instance, I could say

IIf([PersonID]="",0,Count(ENROLLMENT_LIST_ID))

I would think that in this case, "Count" is not accepted by MS Access
either.

Is there another way to do this?
Marcus
*********

Nov 13 '05 #12
First I'd try something easy like:

SELECT Count(ENROLLMENT_LIST_ID) AS ECount, IIf([ECount] = 1, 1, 0) AS
Enrol, ...

James A. Fortune

Nov 13 '05 #13
You could use something like this:
SUM(IIF(ENROLLMENT_LIST_ID)=0,0,1)

Or, it might be appropriate to add a criteria line to your whole query:
HAVING ENROLLMENT_LIST_ID>0
"Marcus" <to*******@yahoo.ca> wrote in message
news:11*********************@o13g2000cwo.googlegro ups.com...
ENROLLMENT_LIST_ID is not always 1 or 0. ENROLLMENT_LIST_ID is a
number that is assigned to a student when they register for a course.
So, ENROLLMENT_LIST_ID could be 914131, or 56787 etc.

Essentially, I use Count(ENROLLMENT_LIST_ID) to determine how many
students are in a course. Really what I need to do is

IIf(Count(ENROLLMENT_LIST_ID) = 1, 1, 0)

but this is not accepted in MS Access, as I get an error when I run it.
The error says that "Count" is not allowed in this circumstance.

To determine whether a Count(ENROLLMENT_LIST_ID) is "1" (one student
registered in the course) or "0" (no students registered in the
course), I should really be determining whether any studentIDs are
associated with Count(ENROLLMENT_LIST_ID). For instance, I could say

IIf([PersonID]="",0,Count(ENROLLMENT_LIST_ID))

I would think that in this case, "Count" is not accepted by MS Access
either.

Is there another way to do this?
Marcus
*********

Nov 13 '05 #14

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

Similar topics

10
by: Tank | last post by:
First off let me say that I am by no means a skilled programmer so i probably have made a dozen mistakes in my attempt at coding my problem. I will tell you the problem so that you have an idea of...
5
by: samik_tanik | last post by:
I need to export a datagrid to Excel. I could did this. But, also need to keep the leading zeros in the data. How can I acheive this? Any help would be appreciated. -- Thanking you in...
12
by: jkearns | last post by:
Hello, I made a report from a crosstab query following the steps onlined in MSDN's Solutions.mdb example. I now have a dynamic crosstab report (great!), but with one minor problem. I cannot get...
2
by: - Steve - | last post by:
I have a situation where when a checkBox is unchecked, I want a textbox to become enabled and vice-versa. The text box remains disabled/enabled until I refresh the page though. What else do I...
6
by: Rich Raffenetti | last post by:
How can one format an integer into a hex string with leading zeros? Suppose an integer is 512 which in Hex is 200. I wish to print the 4-byte integer as 0200 or even 0x0200. The HEX function...
0
by: keithb | last post by:
I posted this question earlier with an unclear predicate. Let me give it another shot: I have found that unless I re-create dynamically added controls on every postback, I am unable to access...
38
by: Mark Dickinson | last post by:
I get the following behaviour on Python 2.5 (OS X 10.4.8 on PowerPC, in case it's relevant.) (0.0, 0.0) (-0.0, -0.0) I would have expected y to be -0.0 in the first case, and 0.0 in the...
0
by: Monty | last post by:
Hi All, I am having a problem with leading zeros being stripped from fields in a CSV file when I bring them in using Jet/OleDB. In VB.Net/VS 2008, I am accessing a CSV file like so: sSQL =...
6
by: Paul K | last post by:
Hi I have a report that is used a sub-report in a primary report. This sub-report shows item usage by month and then calculates a dollar usage based on the item unit cost. The sub-report has two...
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.