473,395 Members | 1,637 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.

Crosstab Queries: Show rows with no values in columns

I have a crosstab query of events by month, and many months do not have any events. How can I make the crosstab show the months (crosstab rows) that don't have any events? Is there a shortcut? Here is the code:

TRANSFORM Val(nz(Count(Event),0)) AS CountOfEvent
SELECT Format([Date],"yyyy-mm") AS MY
FROM dbo_Table
GROUP BY Format([Date],"yyyy-mm")
PIVOT dbo_Table.Event;


Thanks for any help that anyone can give, I'm stumped! Surely there is an easy solution to this simple need.
Nov 13 '06 #1
4 11912
NeoPa
32,556 Expert Mod 16PB
Not really.
You would need to create a recordset which included all the dates between the first and last found in your dataset.
With this you would need to form a query based on this new dataset with a LEFT JOIN to your old one.
This would produce rows for each date but 'empty' dates would have Null values for all other fields.
When transformed I would expect this to give you what you're after.

Never confuse 'easy for humans to understand' with 'easy for an RDBMS to process'.
They're rarely even similar.
Nov 13 '06 #2
MMcCarthy
14,534 Expert Mod 8TB
Try this:

TRANSFORM Val(nz(Count(Event),0)) AS CountOfEvent
SELECT dbo_Table.Event
FROM dbo_Table
GROUP BY dbo_Table.Event
PIVOT MonthName(month([Date])) IN ("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
Nov 13 '06 #3
Never confuse 'easy for humans to understand' with 'easy for an RDBMS to process'.
They're rarely even similar.

Thanks, that does seem to do the trick. I was just fantasizing that I could have some easy command like "show all". :-)
Nov 13 '06 #4
I am also trying to do something similiar, but am not really familiar with cross tab reports. I ran the Wizard, but I have an extra field in my query that I don't want.

Basically, I need to run a query of a listing of policies with review dates (which are actually review years). I need these years listed in columns, so my query should ultimately look like this:

Policy Name 2004 2005 2006
A x
B x
C x

I had someone tell me this was a cross tab query. This sql statement is below. One of my problems is that I have a column in my results under the heading of <>. Why is this? Also, what is the Max IIf statement?

Thanks,
Dawn



TRANSFORM Max(IIf([Year Policy Reviewed]>0,"X","")) AS [Select]
SELECT qryLocalPolicyReviewforReport.[Policy Name], qryLocalPolicyReviewforReport.[Policy Category], qryLocalPolicyReviewforReport.[Policy Type], qryLocalPolicyReviewforReport.[Policy Description]
FROM qryLocalPolicyReviewforReport
GROUP BY qryLocalPolicyReviewforReport.[Policy Name], qryLocalPolicyReviewforReport.[Policy Category], qryLocalPolicyReviewforReport.[Policy Type], qryLocalPolicyReviewforReport.[Policy Description]
PIVOT qryLocalPolicyReviewforReport.[Year Policy Reviewed];
Jan 3 '07 #5

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

Similar topics

6
by: Dave | last post by:
I came across an article in SQL Mag about Crosstab Queries. It works great in Query Analyzer, but I'm stuck on how to use it in an Access ADP. I need to use it as a Recordsource in a form and...
2
by: James Neumann | last post by:
Environment: Access 2k, win2k Business Problem: I have to display returns on investments made over a period of years, and show the amount of return earned on each investment by year. For...
1
by: Nathan Bloomfield | last post by:
Does anyone know if there is any documentation which relates to Access2k + ? or can anyone help adjust the code? I am having trouble converting the DAO references. TITLE :INF: How to...
15
by: Richard Hollenbeck | last post by:
I tried to ask this question before on the 14th of January but I never got a reply. I'm still struggling with the problem. I'll try to rephrase the question: I have a crosstab query with rows...
2
by: deejayquai | last post by:
Hi I'm trying to produce a report based on a dynamic crosstab. Ultimately i'd like the report to actually become a sub report within a student end of year record of achievement. The dynamic...
2
by: Nenad Markovic | last post by:
Hi everybody, When executing a Crosstab Query I see only rows (defined in a row heading) that have values (defined in value field) in at least one column (defined as column headings). How can...
4
by: m.wanstall | last post by:
I have a crosstab query that compiles data for Months of the year. I have a stacked select query on top of that crosstab query that uses the latest 2 months data and exports it to a fixed length...
4
by: mattlightbourn | last post by:
Hi all, I have a problem which has been driving me nuts. Crosstab queries! I have a database witch a few different tables to do with garment manufacturing. I have a table for a client...
14
ollyb303
by: ollyb303 | last post by:
Hi, I am trying to create a dynamic crosstab report which will display number of calls handled (I work for a call centre) per day grouped by supervisor. I have one crosstab query (Query1) which...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...

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.