473,659 Members | 2,632 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 2391
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(qKaize n.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
7242
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 Out Investment?here is the attachment of my image for the sample table and the query that i created..please help me...i am doing this table and query for almost 2 months...i beg you all please..thank you in advance...
3
1576
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 supplied by 4 different tables. Table 1 = Holidays I use the form to print a blank calendar (blank = does not include scheduling info). Holidays are treated as part of a blank calendar like you would buy for your wall at home. Table 2 = Events
4
2430
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
3402
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 to plan to keep the back-end of an Access database in 2003 format while gradually updating client machines from Office 2003 to Office 2013. The front-end is pretty simplistic. It has about a dozen forms, some or all created in the 90s, no queries...
0
1680
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
2686
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 the curve, and I also heard it had much better functionality for touch screen devices which I imagine are only going to get more and more popular. I have noticed a few bugs so far that I was wondering if anyone else has seen or knows how to fix. The...
3
1459
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 leaving the FK field blank and it has a default value that doesn't have a related record in the other table. Is there a way to turn off this "helpful" feature that Microsoft has added? I just had to go through 40 table looking for all the number...
6
1911
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
8341
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8751
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8539
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8630
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6181
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4176
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4342
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2759
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 we have to send another system
2
1982
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.