INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

How to combine these two elements into a select query 

How to combine these two elements into a select query 

(OP)
How can I make the SUM of a numeric field (Number_2017) in which NULL records and BLANK records counted as 0

I tried this for the NULL-records :
SELECT sum(IIF(ISNULL (Number_2017),0,Number_2017)) AS TotalNumber FROM Tablematch
but how to combine it with the 'blanks' (=string) ?

Thanks - Leifoet

RE: How to combine these two elements into a select query 

You should be able to use:

CODE --> sql

SELECT sum(Number_2017) AS TotalNumber 
FROM Tablematch; 

If you have all nulls, you can try:

CODE --> sql

SELECT Nz(sum(Number_2017),0) AS TotalNumber 
FROM Tablematch; 

Having a field named Number_2017 suggests there might be a Number_2016 etc which is typically not good table design.

Duane
Vevey, Switzerland
Hook'D on Access
MS Access MVP 2001-2016

RE: How to combine these two elements into a select query 

I don't understand - if you're doing a sum making nulls or blanks zero will have no effect on the end result? perhaps you meant to count not sum? in which case

SELECT Count(IIf(IsNull([Number_2017]),0,IIf(([Number_2017])="",0,[Number_2017]))) AS TotalNumber
FROM Tablematch;

RE: How to combine these two elements into a select query 

I agree there seems to be a misunderstanding however:

CODE --> sql

SELECT Count(IIf(IsNull([Number_2017]),0,IIf(([Number_2017])="",0,[Number_2017]))) AS TotalNumber
FROM Tablematch; 
is the same as

CODE --> sql

SELECT Count(*) AS TotalNumber
FROM Tablematch; 

If Number_2017 is a numeric field, it will never be "". The simple solution for changing a Null to 0 is by using Nz(Number_2017,0).

Duane
Vevey, Switzerland
Hook'D on Access
MS Access MVP 2001-2016

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close