If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > twelve month array

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-14-05, 10:08
Smokestack Smokestack is offline
Registered User
 
Join Date: Nov 2005
Posts: 5
twelve month array

I have a pivot table query returning the count of services done per model and region, per month for a twelve month array.
I have to run this query monthly and don't want to be rewriting this query for each new date parameter. So this is what I came up with:

PARAMETERS RecordDate DateTime;
TRANSFORM Count(mscqrySurveyServiceLaser.ServiceID) AS [Count of ServiceID]
SELECT ModelGroupNew.ModelGroup, mscqrySurveyServiceLaser.Region
FROM mscqrySurveyServiceLaser INNER JOIN ModelGroupNew ON mscqrySurveyServiceLaser.ModelNumber = ModelGroupNew.ModelNumber
WHERE (((mscqrySurveyServiceLaser.Region)<>"Unknown") AND ((mscqrySurveyServiceLaser.ServiceDate)>=[InstallationDate] And (mscqrySurveyServiceLaser.ServiceDate)>DateAdd("yy yy",-1,[RecordDate]) And (mscqrySurveyServiceLaser.ServiceDate)<=[RecordDate]) AND ((mscqrySurveyServiceLaser.ServiceType)<>"Factory Config.") AND ((mscqrySurveyServiceLaser.RecordDeleted)=False))
GROUP BY ModelGroupNew.ModelGroup, mscqrySurveyServiceLaser.Region
PIVOT Format([ServiceDate],"_yyyymm_");

The problem is that if there were no services in any month within the parameters, then the month naturally does not appear. I'd like it to do so anyway, but can't think of clean solution. I somehow need to define that all months be shown, regardless of null values and without counting services outside of my date parameters.

Any ideas out there?
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On