Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Report Design
Message Icon Topic: default date Parameter Post Reply Post New Topic
Author Message
KevinKD
Newbie
Newbie


Joined: 20 Jun 2012
Location: India
Online Status: Offline
Posts: 9
Quote KevinKD Replybullet Topic: default date Parameter
     Posted: 25 Jun 2012 at 8:37pm
Hi,

I have two input date parameters in my report. First parameter is 'admission start date' second one is 'admission end date' . I am passing these date values to my SQL query to pull the data within the selected date range. Now, can I have the 'admission From date' to default to first day of the previous month and 'Admission End date' default to Last day of the previous month. If require the parameters can be changed otherwise to the default date.

CAn anyone please tell me what all the changes i need to do in my SQL code and Crystal report?

IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 26 Jun 2012 at 3:23am
There is no simple way to default date parameters to a date that is relative to the current date.  You have to use a formula to get the default values.
 
If your report is not based on a stored procedure, you can do the following:
 
1. Create two date parameters that have a default value of something like 1/1/1900 - this date should be out of the range of the dates you would expect to see on your report.
 
2.  Create two formulas - one for the start date and one for the end date.  The start date might look something like this:
 
DateVar StartDate;
If {?Admission Start Date} = Date('1/1/1900') then
(
  StartDate := DateAdd('m', -1, CurrentDate);
  StartDate := Date(Year(StartDate), Month(StartDate), 1);
)
else
  StartDate := {?Admission Start Date};
StartDate
 
You'll do something similar for the end date - I recommend getting the first day of the current month and subtracting 1.
 
3.  In the Select Expert, edit the selection formula so that it looks something like this:
 
{MyTable.DateField} in {@StartDate} to {@EndDate}
 
If you're using a stored procedure to get the data for your report, there are a couple of other things that you need to do.
 
-Dell
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