473,507 Members | 2,388 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Access 2013 query has blanks when I need to display a zero

10 New Member
I have a query that is counting the number of records that fall between two dates as specified in a form using two combo boxes. The query is grouped by two categories, value stream and department. I need to return a count for each department. It works great if there is a record, but I need to show zero if there are no records. I'm combining this with two other similar queries to make a report which uses the values to calculate another value so I need zeroes not blanks. Here is the sql:

Expand|Select|Wrap|Line Numbers
  1. SELECT Count(qKaizen.Rejection) AS CountOfRejection, qKaizen.Department, qKaizen.ValueStream
  2.  
  3. FROM qDepartments LEFT JOIN qKaizen ON qDepartments.DeptName = qKaizen.Department
  4.  
  5. WHERE (((qKaizen.Rejection) Between Nz([Forms]![fKaizenTurns]![tStartDate],#4/1/2015#) And Nz([Forms]![fKaizenTurns]![tEndDate],Date()+1)))
  6.  
  7. GROUP BY qKaizen.Department, qKaizen.ValueStream;
Please help!
Nov 2 '15 #1
7 2385
zmbd
5,501 Recognized Expert Moderator Expert
would you mind posting a generic set of results, say, two records?
Use the [CODE/] button to enclose your table and spaces to format the columns (not the tab key, the tabs won't stay :) )

My first thought here is a UNION clause pulling DISTINCT 0,null,null; however, I'm not sure of the formatting and what you would most likely see in the query for a zero return is
Expand|Select|Wrap|Line Numbers
  1. [CountOfRejection][Department][ValueStream]
  2. [      0         ][    ?     ][     ?     ]
Which is not what I suspect you are after.

The vba function NZ() in the SQL can slow things down on large records... you might consider:
iif([Forms]![fKaizenTurns]![tStartDate] Is Null,#4/1/2015#,[Forms]![fKaizenTurns]![tStartDate])

another consideration is the use of the Between, you can miss some data depending how the data set is entered. you should consider using the inequality:
>=[startdate] < [enddate]+1[

This has cause me some grief in the past because our lab is a 7d/24h operation and the lab results have a date+time stamp and the form I was using at the time to pull reports didn't take that into consideration... really, one would think that the Between would pull from midnight to midnight for the indicated dates :( . (MVP Allen Browne shows an example of such a construct in the first half here: Limiting a Report to a Date Range I don't see any reason to use the huge function in the second 1/2 of the post for your query.)
Nov 3 '15 #2
jpreator
10 New Member
If I understood what you were asking here is an example of how the report turns out. It leaves blanks and so I cannot get the turns calculation to calculate.

Expand|Select|Wrap|Line Numbers
  1. [Value Stream] [DeptName] [Rej][Comp]/[Sub]=[Turns]
  2. [Centerfire  ] [ CFAA   ] [   ][  1 ]/[ 2 ]=[ 0.5 ]
  3. [            ] [ CFMP   ] [ 3 ][ 14 ]/[ 3 ]=[ 4.7 ]
  4. [            ] [ Plating] [   ][  1 ]/[   ]=[     ]
  5.  
Nov 3 '15 #3
jforbes
1,107 Recognized Expert Top Contributor
I think the following should work for you:
Expand|Select|Wrap|Line Numbers
  1. SELECT NZ(Count(qKaizen.Rejection), 0) AS CountOfRejection, qKaizen.Department, qKaizen.ValueStream
Nov 3 '15 #4
jpreator
10 New Member
Thank you both for your replies, that seems to have done the trick.
Nov 3 '15 #5
zmbd
5,501 Recognized Expert Moderator Expert
J:
I had thought of that ( NZ(Count(qKaizen.Rejection), 0) ) however, I've had that fail on me a few times when I use a named field and only sometimes works with NZ(Count(*), 0).

Funny thing... I just went back in to one of my production databases to see how I was handling a similar situation (this is live SQL in one of my databases, one nice thing about the normalized data, nothing but generic numbers!):

Expand|Select|Wrap|Line Numbers
  1. SELECT tbl_batch.batcher_ID
  2.    , tbl_batch.batch_point
  3.    , Count(tbl_batch.Date_tested) 
  4. AS CountOfDate_tested
  5. FROM tbl_batch
  6. GROUP BY tbl_batch.batcher_ID
  7.    , tbl_batch.batch_point;
  8.  
Part of the actual data set (This is actually a temp table that is used later in a crosstab - inherited this database nightmare):
Expand|Select|Wrap|Line Numbers
  1. PK      batcher_ID      batch_point     Date_tested
  2. 971      1               1               10/26/2015
  3. 972      1               2    
  4. 973      1               3               10/26/2015
  5. 989      1               4               10/27/2015
  6. 990      1               4               10/28/2015
  7. 991      1               4               10/30/2015
  8. 987      2               1    
  9. 998      2               2    
  10. 999      2               3    
  11. 1010     2               3    
  12. 1511     2               3    
  13. 1512     3               5    
  14. 1513     3               5    
  15. 1514     3               5    
  16. 1515     3               4    
  17. 1516     3               5
However, I use the query to determine pending batches so this is my actual return...
Expand|Select|Wrap|Line Numbers
  1. batcher_ID     batch_point     CountOfDate_tested
  2. 1               1               1
  3. 1               2               0
  4. 1               3               1
  5. 1               4               3
  6. 2               1               0
  7. 2               2               0
  8. 2               3               0
  9. 3               4               0
  10. 3               5               0

Now when I put a conditional to search for test results between two dates then I get tend to get the null record row and I have code to check for no record in the report.

I've gone in and check two of my other databases and they have this same construct and results...

Could it be the join in OP's post that is causing the issue?
Nov 3 '15 #6
jforbes
1,107 Recognized Expert Top Contributor
Z,

In my experience, it's best not to Count against a column that can contain Nulls, because nulls wont be included in the count. Also the * operator can cause extra columns to be returned, slowing things down, not always, but it can. So experience has taught to count the primary key whenever possible.

I'm not sure what the difference is between what you and jpreator are doing, but I would imagine it has something to do with SQL initializing the variable for the Count.

...Again, experience has guided me towards counting a PK, I've forgotten the specific cases, but I imagine something like this has happened to me before. =)
Nov 3 '15 #7
zmbd
5,501 Recognized Expert Moderator Expert
...Again, experience has guided me towards counting a PK, I've forgotten the specific cases, but I imagine something like this has happened to me before. =)
Good point about using the primary key for the count. In my case I needed both missing and entered dates... if it had returned a null instead of a number it wouldn't have been an issue for me.

but I would imagine it has something to do with SQL initializing the variable for the Count.
It would be great to know what was happening here instead of what might be a fluke that could break my databases later :-( !
That may be a topic for a new thread; however, if we can figure this out, it might be the solution to jpreator question?!

Also the * operator can cause extra columns to be returned
The asterisk... unless on a very limited table/query - I too avoid it like the plague that it can be :)
Nov 3 '15 #8

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

Similar topics

0
7229
by: steveradaza | last post by:
Sir,Good Day..I am a newbie here and i am just learning the usage of microsoft access..can you help me solve my problem in making a running balance in a query of microsoft access 2013 of my In and...
3
1570
RockKandee
by: RockKandee | last post by:
I am using the MS Access Calendar in Access 2013, Windows 8. http://bytes.com/topic/access/answers/761255-ms-access-calendarhttp:// Currently I am using 4 calendar forms with the data source...
4
2418
by: nomeepk | last post by:
hi, i am using access 2013, Is there a way i can make this Access Database online, so i can access and use it from anywhere in a Browser? Regards.
5
3398
by: jimatqsi | last post by:
I'm looking for information about compatibility between Access 2013 and Access 2003. I've been approached by a firm that wants to begin upgrading their systems. I want to know if it is reasonable...
0
1670
by: LeoVBNET | last post by:
Hi Because VS 2013 dropped SQL COMPACT databases, I need to convert Access 2013 databases into SQL COMPACT in order to be able to use Linq to SQL in VB 2013. Anybody can help me? Thanks
6
2682
by: GKJR | last post by:
I have been using Access 2013 (in Office 365) with Windows 8.1 for about a month and a half now. I was a little reluctant to switch from 2010 on Windows 7, but I figured I should try stay ahead of...
3
1457
Seth Schrock
by: Seth Schrock | last post by:
I just discovered that Access 2013 puts in a default value of 0 for number fields. This is very annoying when relating fields and you get an error when trying to insert records thinking that I'm...
6
1907
by: msilva100 | last post by:
Hello, I need to have remote access to a MS Access 2013 Database running on a Windows 7 Server. Can someone kindly recommend a remote access tool? Thank you.
0
7111
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
7319
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
7376
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
7485
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
5042
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
4702
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3191
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
1542
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 ...
0
412
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.