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

Require 0 if none found via query

Hi, I have a table ACT_TYPE_SC that I am trying to query, it has many possibilities but I want to check for certain criteria ie the word "Delay" and if none are found return a zero as this is used later on. I have tried Nz, Isnull but can get no joy only a blank space, please help the complete novice !! thanks
Attempts;
Expand|Select|Wrap|Line Numbers
  1. Field:Nz([SA_ACT_TYPE.ACT_TYPE_SC],"0")
or
Expand|Select|Wrap|Line Numbers
  1. Field:Count(*(Nz([SA_ACT_TYPE.ACT_TYPE_SC],0)))
or
Expand|Select|Wrap|Line Numbers
  1. Field:IIf(IsNull([SA_ACT_TYPE].[ACT_TYPE_SC]),0)
all with Criteria: Like "Delay*"
Feb 1 '13 #1

✓ answered by NeoPa

Your FROM clause is built up using many INNER JOINs. Depending on your data this is likely to restrict the amount of records that result from this query quite substantially. Your HAVING clause further restricts what data can show. You need to look at these issues before wondering why the result isn't zero. There is no zero result because there are clearly no output records for the result to be included in. The query specification is so restrictive that you have no matching/valid data to show at all.

13 1566
NeoPa
32,556 Expert Mod 16PB
Try :
Expand|Select|Wrap|Line Numbers
  1. Field: Nz(Count(*),0)
Of course, this depends on exactly how your query is designed. It would be a good idea to include the full SQL of your query so we can get a better understanding of what you're actually asking. Choose View | SQL in the QueryDef to see and capture the SQL to post.
Feb 1 '13 #2
Hi, thanks for quick response, attached is the SQL (Mod - Removed attachment and included the code properly in the post). the reference to ISO Workday in it is another query regarding dates. Thanks in advance as I have spent days on this. :-(
Expand|Select|Wrap|Line Numbers
  1. SELECT   IIf([Actual_Days]<31,"OnTime","OOPS") AS Result
  2.        , SA_INC_SERIOUS.INC_SERIOUS_SC
  3.        , SA_ITEM.ITEM_SC
  4.        , SA_INCIDENT.DATE_LOGGED
  5.        , SA_INCIDENT.INC_CLOSE_DATE
  6.        , ISO_WorkdayDiff([INC_CLOSE_DATE],[DATE_LOGGED],True) AS Actual_Days
  7.        , [INC_CLOSE_DATE]-[DATE_LOGGED] AS Days
  8.        , Year([INC_CLOSE_DATE]) AS [Year]
  9.        , Month([INC_CLOSE_DATE]) AS Expr1
  10.        , SA_INCIDENT.INCIDENT_REF
  11.        , Count(*(Nz([SA_ACT_TYPE.ACT_TYPE_SC],0))) AS Expr2
  12. FROM     SA_ACT_TYPE
  13.          INNER JOIN
  14.          ((SA_ITEM 
  15.          INNER JOIN
  16.          (SA_INCIDENT
  17.          INNER JOIN
  18.          SA_INC_SERIOUS
  19.   ON     SA_INCIDENT.INC_SERIOUS_ID = SA_INC_SERIOUS.INC_SERIOUS_ID)
  20.   ON     SA_ITEM.ITEM_ID = SA_INCIDENT.ITEM_ID)
  21.          INNER JOIN
  22.          SA_ACT_REG
  23.   ON     SA_INCIDENT.INCIDENT_ID = SA_ACT_REG.INCIDENT_ID)
  24.   ON     SA_ACT_TYPE.ACT_TYPE_SC = SA_ACT_REG.ACT_TYPE_SC
  25. GROUP BY SA_INC_SERIOUS.INC_SERIOUS_SC
  26.        , SA_ITEM.ITEM_SC
  27.        , SA_INCIDENT.DATE_LOGGED
  28.        , SA_INCIDENT.INC_CLOSE_DATE
  29.        , ISO_WorkdayDiff([INC_CLOSE_DATE],[DATE_LOGGED],True)
  30.        , [INC_CLOSE_DATE]-[DATE_LOGGED]
  31.        , Year([INC_CLOSE_DATE])
  32.        , Month([INC_CLOSE_DATE])
  33.        , SA_INCIDENT.INCIDENT_REF
  34.        , SA_INCIDENT.ASS_SVD_ID
  35. HAVING   (((SA_INC_SERIOUS.INC_SERIOUS_SC)="ITORD 30 DAY")
  36.    AND   ((Year([INC_CLOSE_DATE]))=Year(Date()))
  37.    AND   ((Month([INC_CLOSE_DATE]))=Month(Date()))
  38.    AND   ((Count(*(Nz([SA_ACT_TYPE.ACT_TYPE_SC],0)))) Like "Delay*")
  39.    AND   ((SA_INCIDENT.ASS_SVD_ID)=495))
  40. ORDER BY SA_INCIDENT.INC_CLOSE_DATE
Feb 1 '13 #3
NeoPa
32,556 Expert Mod 16PB
FishFace:
The reference to ISO Workday in it is another query regarding dates.
??? The only thing I see remotely close to "ISO Workday" in your code doesn't look anything like a query reference. ISO_WorkdayDiff([INC_CLOSE_DATE],[DATE_LOGGED],True) appears to be a function of some sort.
Feb 1 '13 #4
It is a holiday/weekend VB script.. It is used later on when I combine two queries which is part of the reason I need to show zero if nothing found... Please ignore it if possible.. thanks
Feb 1 '13 #5
zmbd
5,501 Expert Mod 4TB
Line 11:
Expand|Select|Wrap|Line Numbers
  1. Count(*(Nz([SA_ACT_TYPE.ACT_TYPE_SC],0))) AS Expr2 
and again in line 38:
Expand|Select|Wrap|Line Numbers
  1. ((Count(*(Nz([SA_ACT_TYPE.ACT_TYPE_SC],0)))) Like "Delay*")
Remove the "*". I'm surprised the engine took that construct at all... infact, when I went to verify this, my test db puked a syntax error.

SO, lets take a quick look at the Count() in SQL:
count(*) says count everything and return the number of records.
count([SomeFieldName]) says count everything except null values within the givien field. So, it would seem to me then that: Count(*) would be equal to Count(Nz([SA_ACT_TYPE.ACT_TYPE_SC],0)).
Which, again in my test database, is exactly what happens.

Even with removing the "*" from the code, I'd be surprised to see anything except a "1" as the count returned in line 11.

SO, line 38 will have the same issue as line 11.

as for the remainder of the SQL, I don't have your tables nor dataset in front of me nor have you really defined your issue; thus, I am unable to fathom much more of your SQL... perhaps Rabbit or Neopa will have better understanding.

> Before Posting (VBA or SQL) Code.
> How to ask "good" questions
> POSTING_GUIDELINES: Please Read Carefully Before Posting to a Forum.
Feb 2 '13 #6
NeoPa
32,556 Expert Mod 16PB
Try :
Expand|Select|Wrap|Line Numbers
  1. Sum(IIf(SA_ACT_TYPE.ACT_TYPE_SC Like 'Delay*',1,0))
or :
Expand|Select|Wrap|Line Numbers
  1. Count(IIf(SA_ACT_TYPE.ACT_TYPE_SC Like 'Delay*',1,Null))
Feb 4 '13 #7
zmbd
5,501 Expert Mod 4TB
duh... feeling stupid now... I use that same type of code for the "sub total" and "grand total" in the reports.

These little new-borns are so cute; however, I think that they are draining my intelligence out of my mind along with that bottle every 3 hours!
Feb 4 '13 #8
NeoPa
32,556 Expert Mod 16PB
Z:
These little new-borns are so cute; however, I think ...
How many new ones have you got??!? You talk as if they came in a batch! Crated babies just doesn't sound right :-D
Feb 4 '13 #9
zmbd
5,501 Expert Mod 4TB
Still that "*" is causing a glitch.

--
Only the one new one... but with the twins hitting the 3yr mark... it seems like alot more some days
Feb 4 '13 #10
Gents, thanks for your responses, I still get a blank row, however if enable Totals and use the drop down box I get the option to put a zero in, but it never stays there. so when I run the query it go back to being blank... Almost hair pulling out time !!
Feb 4 '13 #11
zmbd
5,501 Expert Mod 4TB
Then none of your data is matching queries within the realationships you've defined.

Thus the need for your tables and a small amount of sample data.

The data doesn't have to be "real" just representitive... for example it is a common usage for "John M Doe", "Jane H. Doe" amd "John Q. Public" as stand-ins for people names. 555-1212, 555-1234, etc for telephone. 000-00-0001 and so-on for SSN,
Feb 4 '13 #12
NeoPa
32,556 Expert Mod 16PB
Your FROM clause is built up using many INNER JOINs. Depending on your data this is likely to restrict the amount of records that result from this query quite substantially. Your HAVING clause further restricts what data can show. You need to look at these issues before wondering why the result isn't zero. There is no zero result because there are clearly no output records for the result to be included in. The query specification is so restrictive that you have no matching/valid data to show at all.
Feb 4 '13 #13
Sorted... it was the way i had linked the Tables, once i removed the not required and checked the Joins it worked :-) Thanks for all the help !!!
Feb 6 '13 #14

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

Similar topics

2
by: JDJones | last post by:
Using PHP and MySQL. Trying to put a list of categories into a drop down select option of a form like: <form name="form" action="<? print $_SERVER?>" method="get"> <select name="subject">...
3
by: Nick Truscott | last post by:
<? // scoreinput.php - input a match score when match selected from list ?> <html> <head> <basefont face="Verdana"> </head> <body>
3
by: Dalan | last post by:
From reading Access 97 help text, it seems that to do what I need to do will require a Union Query. As this would be my first, I think I might require a little guidance. I have two tables with...
2
by: Buster Chops | last post by:
Hello. Looking for some tips, tricks or help in addressing the following issue. Table 1 has two columns, A and B. Column A is the Key ... column B is the name-value. Table 2 has many rows...
3
by: cobus.lombard | last post by:
Hi All Couldn't find an xpath specifig UG, so I'm posting this here. I have XML in the following structure: <Assignments> <Assignment> <ID>123</ID> <Description>Test Assignment...
3
by: info | last post by:
Hi, I have one table name: art column: symbol_art price1 price2 ----------- ------- ------- AG-0001 20 40 AG-0001S null null
0
by: barmatt80 | last post by:
I am trying to write a program that the user can select an approval date and using that approval date, it would query a sharepoint list and return that list item that corresponds with that list item....
11
by: Jialiang Ge [MSFT] | last post by:
Hello Peter, I once came across the same error "ExecuteReader requires the command to have a transaction when the connection assigned? with running two threads talking with the database. There...
1
by: =?ISO-8859-1?Q?Arne_Vajh=F8j?= | last post by:
Peter wrote: The DB2 ADO.NET provider should be XCOPY deployment. Isn't it ? Arne
1
by: escapersky | last post by:
I have a database that i've been entering and I need to show how many unique entries I have entered prividing the date range. The database includes date, productID, locationID, quantity etc. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
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
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,...

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.