Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Null Trouble

Status
Not open for further replies.

CTOROCK

Programmer
May 14, 2002
289
US
I am having trouble with a query returnig a 0 when there is a null. I have a Q_count-Single:

SELECT Tbl_Fundraiser.Campaign, Count(Tbl_Fundraiser.[Fund Type]) AS SngCount, Tbl_Fundraiser.[Fund Type]
FROM Tbl_Fundraiser
GROUP BY Tbl_Fundraiser.Campaign, Tbl_Fundraiser.[Fund Type]
HAVING (((Tbl_Fundraiser.Campaign)="10") AND ((Tbl_Fundraiser.[Fund Type])="single"));

... But the value is null, there is none with my criteria.
I've tried this:

Insp Count: IIf(IsNull([InspCount]),"0",[InspCount])
or

IIf(nz([InspCount]),"0",[InspCount])
or

Count: Nz([InspCount])

I've done this in the same query and tried to create a seperate query that pulls the null info and I never get a thing. Can anyone help? Thanks!
 
[smarty] There are two problems with Null:

- The Nz function, as you use it, returns an empty string if the field is null. I do not know what 'if "" then ...' does.

- The second is a major bug that microsoft is proud of. It is called 'Null propagation'. It means that Null, used in an expression, will return Null for the whole expression in most of the times. This also implies that comparison operators (=, >, etc.) do NOT HAVE A BOOLEAN RETURN VALUE. Instead, they are variants: They can be True, False OR NULL.
This also works for the iif() function.
Examples:

Code:
if &quot;What?&quot;<>Null then print &quot;Clearly different.&quot;
: (nothing happens here)

Code:
print not(False)
:
Code:
True

Code:
print not(Null)
:
Code:
Null

Code:
print 5+Null
:
Code:
Null

Hope this helps
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top