473,503 Members | 6,587 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Access 2003, how do I show "zero" values in a query, where the field is calculated?

2 New Member
SELECT Dates.[Game Date], Sum(1) AS [Adj Away Wins]
FROM Dates LEFT JOIN [NBA Table] ON Dates.[Game Date] = [NBA Table].[Date of Game]
WHERE ((([NBA Table].[Home Score])<[Adj Away Score]))
GROUP BY Dates.[Game Date];

I'm doing a sports database, for entertainment and to learn Access, so hopefully this is an easy fix. I have a Dates table, with each date of the year. I have another table with raw game data for each basketball game.

Let's say one day there are 5 games. Let's also assume that all 5 of these games are won by the "Home Team". Because "Away Team" has 0 wins on this date, when I SUM the total for this given date, it's 0 and will not show up in my query. I want the 0 to be present, so that later on I can run mathematical operations on this number.

I was able to use an IIf statement on other queries, where no calculations were done, but can't figure this one out.

Thanks in advance and let me know if I need to post more.
Dec 21 '09 #1
4 11242
Delerna
1,134 Recognized Expert Top Contributor
I think I follow your design ?


How about this
Expand|Select|Wrap|Line Numbers
  1. SELECT a.[Game Date], 
  2.        Sum(  IIF( b.[Home Score] < b.[Adj Away Score] , 1 , 0 
  3.            ) AS [Adj Away Wins]
  4. FROM Dates a
  5. LEFT JOIN [NBA Table] b ON a.[Game Date] = b.[Date of Game]
  6. GROUP BY [Game Date];
  7.  
There would be otherways too.
Some will run faster than others.
Maybe you should try to find a few other ways and see which performs best
Dec 22 '09 #2
Delerna
1,134 Recognized Expert Top Contributor
Oh, and the real reason that the dates that had no away wins were missing was because of this

WHERE ((([NBA Table].[Home Score])<[Adj Away Score]))

which filters every record, where the away team lost, out of the result, prior to doing the aggregation.
So if no away team won on a particular date then every record for that date
gets filtered out of the result.

That filtering occurred before the sum() so its really not because the sum equalled 0.
I know what you mean though.
Dec 22 '09 #3
WolverYanks
2 New Member
Thanks a bunch. This info was right on. I never thought to embed the IIF inside the SUM expression.

Thanks again!
Dec 22 '09 #4
MrDeej
157 New Member
Even simpler. In the query put "nz([calculated field];0)"

";0" or ";anything" will show if [calculated field] is null
Dec 22 '09 #5

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

Similar topics

16
1721
by: PeteCresswell | last post by:
I was happily coding along, putting some calculation results (rolling annualized rates of return - too compute-intensive to calculate on-the-fly - had tb staged beforehand via a batch job) into...
13
3959
by: royaltiger | last post by:
I am trying to copy the inventory database in Building Access Applications by John L Viescas but when i try to run the database i get an error in the orders form when i click on the allocate...
1
6439
by: laredotornado | last post by:
Hi, I'm using PHP 4.4.4 on Apache 2 on Fedora Core 5. PHP was installed using Apache's apxs and the php library was installed to /usr/local/php. However, when I set my "error_reporting"...
7
16340
by: PW | last post by:
Hi, I have a form with unbound fields on it. The user selects a record from a recordset and I populate the unbound fields. When I try to change the unbound quantity text box, Access 2003 tells...
2
3966
by: Angus | last post by:
I am trying to change the selection in Javascript - but this HTML element is not a standard option control. On the web page it looks like a dropdown list - and you click on the right hand down...
3
1642
by: roger.dunham | last post by:
Hi there, I am writing an application that performs calculations on records within a data table. There may be many records in a data table. There are situations where the calculation may not...
5
5290
by: Spetman | last post by:
I’m having trouble using MS Access 2003 to accomplish something that I thought would be relatively easy: I’m trying to create a query that will give me the projected balance of an account (such as a...
4
2646
by: daved | last post by:
SOLUTION NEEDED FOR ACCESS 2003 / VBA, NOT FOR ANY VERSION OF VB. I need to differentiate between the Enter key on the main keyboard and the numeric keypad and obviously tried using...
1
2837
by: katanah | last post by:
I am using Access, 2003. I have an entry form (single form) with a date field. I would like the user to be able to enter: 115 08 and have Access store and display the date as: 11/05/08, even...
0
7193
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
7316
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
7449
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...
1
4992
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...
0
3160
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3148
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1495
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
728
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
371
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.