Create a table named Count with numbers zero through 31. The query below
will generate a list of date for the current month. You can easily change to
list last months days.
SELECT Date()-Day(Date())+1+[count] AS Date_Volume, Date()-Day(Date())+1 AS
Start, DateAdd("m",1,Date()-Day(Date())+1)-1 AS [End]
FROM [Count]
WHERE (((Date()-Day(Date())+[count])<DateAdd("m",1,Date()-Day(Date())+1)-1))
GROUP BY Date()-Day(Date())+1+[count], Date()-Day(Date())+1,
DateAdd("m",1,Date()-Day(Date())+1)-1;
This query sums the volume for Dept 10050470100 for the previous month and
includes all days of the month.
SELECT Volume.Day, Volume_Dates.Date_Volume, Volume_Dates.Start,
Volume_Dates.End, Sum(IIf([Dept]="10050470100",[UW_Volume],0)) AS [Volume
Total], Volume.Dept
FROM Volume_Dates LEFT JOIN Volume ON Volume_Dates.Date_Volume = Volume.Date
GROUP BY Volume.Day, Volume_Dates.Date_Volume, Volume_Dates.Start,
Volume_Dates.End, Volume.Dept
ORDER BY Volume_Dates.Date_Volume;
DEI said:
Thank you Douglas and Vincent, but I knew I could create another table and
join, etc., I just thought there might be an easier solution.
Karl - here is my SQL statement, again it skips dates because no data exists
for certain days. The first two fields show the day of the month and the
actual date, respectively.
Thanks for the help.
DEI
SELECT VOLUME.Day, VOLUME.Date, Sum(VOLUME.UW_Volume) AS Volume
FROM VOLUME
GROUP BY VOLUME.Day, VOLUME.Date, VOLUME.Dept
HAVING (((VOLUME.Dept)=10050470100));
KARL DEWEY said:
Post you SQL statement and I will fill it out for you.
SELECT CVDate([Enter start date])+[Count] AS [My Dates]
FROM [Count]
WHERE (((CVDate([Enter start date])+[Count])<=CVDate([Enter end date])));
DEI said:
I have a query that shows values for each date in a month, sorted by date.
True to form, however, SQL only retrieves dates that exist in the table. I
would like to show a null, or zero value for each date for which there is no
data. Is there a way to do this with a select query similar to using an "In
(" clause in a crosstab query to define column headings, regardless if data
exists for it?
Thanks in advance.
DEI