SynapseVampire,
I don't bother having a period table. I use the following stored procedure to generate the dates on the fly:
In the referenced table in the database where I use the stored procedure (MagicTSD Help Desk Software) There are opened dates and closed dates. As you will see the first two parameters are the Start Date and the End Date. Crystal will prompt you for these when you link it. So this can generate a month or a year or years, your choice. It will generate all the dates in between the start date and end date for use on the report.
Here is the code (MS SQL 2000):
if exists (select * sysobjects where id = object_id('dbo.sp_CalReport') and sysstat & 0xf = 4)
drop procedure dbo.sp_CalReport
GO
CREATE PROCEDURE dbo.sp_CalReport
declare
@start datetime,
@end datetime,
@counter int
set @start = '1/1/2001'
set @end = '1/30/2001'
set @counter = 1
select dates.date
from
(
-- This select produces a sequence of dates starting from @start
select DATEADD(dd, seq.id, @start) as date
from
(
-- This select produces a sequence from 0 to 399 using Cartesian product.
select (a0.id + a1.id + a2.id) as id
from
(select 0 id union select 1 union select 2 union select 3 union select 4 union select 5 union
select 6 union select 7 union select 8 union select 9) a0,
(select 0 id union select 10 union select 20 union select 30 union select 40 union select 50 union select
60 union select 70 union select 80 union select 90) a1,
(select 0 id union select 100 union select 200 union select 300) a2
-- ...
) seq
) dates
left join _SMDBA_._TELMASTE_
on dates.date between [DATE OPEN] and coalesce([Closed On], [Closed On], '12/31/9999')
where
dates.date between @start and @end
group by
dates.date
order by 1
I did the above, because I had the issue of showing all the dates and counts of calls on dates even if there were none!
This works like a charm...
ro
(when copying the stored procedures make sure those comments are on one line - the posting here sometimes changes it)
Rosemary Lieberman
rosemary@microflo.com,
Microflo provides expert consulting on MagicTSD and Crystal Reports.