Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Report Design
Message Icon Topic: populate date range on the fly Post Reply Post New Topic
Author Message
johnwsun
Senior Member
Senior Member


Joined: 28 May 2008
Location: Australia
Online Status: Offline
Posts: 179
Quote johnwsun Replybullet Topic: populate date range on the fly
     Posted: 31 Oct 2012 at 3:36pm
Hi,
 
I am trying to display all dates on a monthly basis which is supposed to have both value or null value in CR 2008( if null just display 0):
Date             total count
1/2/2012        0
2/2/2012        4
3/4/2012        1
4/4/2012         0
..
30/4/2012       5
I am trying to pass parameters in date ( from date, to date) from a stored procedure (execute on the database), then populate those date range on the fly:
 

ALTER PROCEDURE [dbo].[sp_Report_Dates]

 
   @sFromDate datetime,
      @sToDate datetime
AS

BEGIN
 
 SET NOCOUNT ON;

 
   with ReportDates(calendar_date) as
   (
 SELECT CAST(@sFromdate as datetime )
 UNION ALL
 select calendar_date + 1
 from ReportDates
 where calendar_date < @sToDate
 )
 SELECT  ReportDates.calendar_date, E.LDTE, E.BRW FROM OND E
 RIGHT OUTER JOIN
 ReportDates ON E.LDTE = ReportDates.calendar_date
  
END

Problems:
I think I should use date instead of datetime, however, the select calendar_date + 1 won't work;
My original goal is create a temp table ( one column only )  then populates the date range on the fly, then link that table ( date field) with another table's date field on right outer join;
the above SP doesn't seem to be working at all.
Please advise if there is a better way, such as create a table and/or view on the fly; or perhaps use SQL command from Crystal Report?Thanks in advance.
 
JS
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 01 Nov 2012 at 8:18am
if you have a calendar with all the dates in it, I would think that you would do something like:
 
select
  calendar.date,
  report.data
from calendar
  left join report
    on report.date = calendar.date
where calendar.date between @startDate and @endDate
 
 
since you want all the date irrespective of if there is any data associated them...and any data, if it exists.
 
HTH
IP IP Logged
johnwsun
Senior Member
Senior Member


Joined: 28 May 2008
Location: Australia
Online Status: Offline
Posts: 179
Quote johnwsun Replybullet Posted: 01 Nov 2012 at 5:16pm
yes,
 I have created calendar table populated with dates.
I found the customer's requirment cannot be achieved:
I was asked to group by dates, then group by borrower, then in the detail section - list items, e.g.
 
date           name        total daily count           cocurrent count
1/1/2012                      2
                 xyz                                                   1
                 abc                                                   1 
2/1/2012                      0   
3/1/2012                      1
                  xyz                                                   1
 
Is the above possible?
 
JS
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 02 Nov 2012 at 5:51am
you know the data better than I.
I would have thought that report was doable (not knowing what a cocurrent count is)
it almost looks like it is group by date, group by customer (and just display the customer info in the group footer (easiest place for a count)), but what do I know ;)
 
again, you know the data.
 
HTH
IP IP Logged
johnwsun
Senior Member
Senior Member


Joined: 28 May 2008
Location: Australia
Online Status: Offline
Posts: 179
Quote johnwsun Replybullet Posted: 11 Nov 2012 at 5:08pm
Hi,
 
I created a view on the SQL database and linked (left outer join)the date field in the view to the calendar table - which achieved the requirement of the customer.
 
JS
IP IP Logged
johnwsun
Senior Member
Senior Member


Joined: 28 May 2008
Location: Australia
Online Status: Offline
Posts: 179
Quote johnwsun Replybullet Posted: 03 Dec 2012 at 12:00pm
Hi my approach is still short of the customer's expectation.
 
The customer wants the next day bringing over the previous days transactions even if the loan is not returned, e.g.
                              total daily count     con loan               issued     returned
1/08/2012  ( group 1)        3
     borrower    (group 2)                          3
                    item 1                                                   1/8/2012    3/8/2012
                    item 2                                                   2/8/2012    3/8/2012
                    item 3                                                   3/8/2012     3/8/2012
 
2/08/2012                         0   ( currently I calculated based the fact there is no trascaction on that day, but the customer wanta it gives the value that indicates there are items  still on loan on that day  regardless there is transaction or not; if there is transaction, it must otherwise adds previous day's )
 
the daily total count is in a formula ( group 1):
if distinctcount({GET_SQIT_LAPTOP_USAGE.ID}, {GET_SQIT_LAPTOP_USAGE.date_value}) = 0 then 0
else
  distinctcount({GET_SQIT_LAPTOP_USAGE.ID}, {GET_SQIT_LAPTOP_USAGE.date_value})
 
the concurrent count for each borrower in a formula ( group 2):
distinctcount({GET_SQIT_LAPTOP_USAGE.ID},{@borrower_names})
 
My query is how I can bring over the previous day's data added togther with or without today's transaction. PLease advise, thanks in advance.
 
JS
IP IP Logged
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum