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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

group by null 2

Status
Not open for further replies.

dinster

Programmer
Apr 12, 2007
54
GB
Hi all, i want to count the records and group them. But this doesnt work if there's empty records in location.

SELECT Sheet4.Location, Count(Sheet4.Location) AS CountOfLocation
FROM Sheet4
GROUP BY Sheet4.Location;


e.g

Location count
test1 5
test2 7
empty 0 (where this should be 4 records)

so how do i group empty records?


cheers
 
You need to get rid of the nulls, so how about:

Code:
SELECT Sheet4.Location, Count(Nz([Location],0)) AS Loc
FROM Sheet4
GROUP BY Sheet4.Location;
 
Use this:
SELECT Sheet4.Location, Count([!]*[/!]) AS CountOfLocation
FROM Sheet4
GROUP BY Sheet4.Location

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
both you guys are wrong

you gots to use IIF(Location='','Empty',Location)

don't get rid of the nulls, count them!

;-)

r937.com | rudy.ca
 
In Access a Null is not equal to '', yesno? :)
 
that's right!

and dinster said "if there's empty records in location" not "if there's null records in location"

my comment about counting them was in response to your suggestion to get rid of them

;-)

r937.com | rudy.ca
 
don't get rid of the nulls, count them!
Rudy, my suggestion counts the nulls !
 
I do not think that your suggestion counts nulls, r937, it counts empty strings, calling them empty, as you pointed out.
 
yes, i know!! it isn't supposed to count nulls!!

have we finally got rid of the nulls?

you started it

;-)

r937.com | rudy.ca
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top