Output a zero when no records are found...?

  • Thread starter Thread starter CSTarqs
  • Start date Start date
C

CSTarqs

Guest
Hey everyone,
Even though I'm going to feel like a moron for not knowing this I'm hoping there is a simple answer. I'm far from a master at access, and seem to be having a little trouble when it come to formatting the output of my query. I have a database made the keeps track of about 200 hundred crime reports. I want to be able to do a query that will output the 15 possible crimes as rows, and then have 4 columns which are the locations of where the crimes happened. And then for the results have how many of crime where commited there. Pretty much in an excel format (see below example). However there are some crimes that have never happened. So there are no records of them. Unfortunatly when i do my query since there are no records, they are not even listed. I need them to list the crime, and place zeros if there are none. Since this probably isn't to clear I'll put a little example below.

Data:

Robbery: 4 on campus, 5 off campus, 6 in city, 0 in apartments
ra**: 0 on cmpus, 3 off campus, 4 in city, 0 in apartments
murder: 0 on campus 0 off campus, o in city, 0 in apartments

When i do my query it looks like this

*********On Campus****Off Campus****In City

Robbery******4***********5***********6
ra**********************3 ***********4

*Notice it doesn't even list the apartments since there are no records that match, the same with murder.

I need the output to look like this:


*****On Campus *****Off Campus ***In City****apartments

Robbery****4 ************ 5********6 ********0
ra*********0*************3********4********0
murder *****0*************0 *******0********0

Any ideas? Thanks!
 
Can't you use the NZ function to return zero?
Post your SQL so we can look at it.
 
Sql...

Here is my SQL for the query. I run the query it dumps out the table for me, then i view it as a pivot table to get my final output.

SELECT Count(Clery.CleryLocation) AS CountOfCleryLocation, Clery.CleryLocation, UCRCrimes.[Clery UCR]
FROM UCRCrimes INNER JOIN Clery ON UCRCrimes.[Crime or Incident] = Clery.[Crime or Incident]
GROUP BY Clery.CleryLocation, UCRCrimes.[Clery UCR];

And where would I implement the NZ function....As I stated before, I'm def a beginner when it comes to access. But I'm working on it!
 

Users who are viewing this thread

Back
Top Bottom