i called it autodating my reports… our issue was that we have a ton of reoccurring reports - monthly, quarterly and anyally and i hated having to schedule these things with the parameters. there would always be one that i forgot to get and they can;t be set to a reoccurring schedule because of the dyanmic dates, so i did the following… let me know if you have questions on it…
How to autodate a report.
Use: There were several old tax reports that were using date parameters for reports that ran on an annual basis. Since the parameters were needed, each report needed to be scheduled with the parameters provided and could not just be left to run rach year without providing the date range. Autodating is using the assumed run date (since these are always run on March 1 for the previous years data) and basing the date parameters off that assumed run date. The date criteria can then be used in the Selection Expert of Crystal Reports to get the desired data rather than a parmaeter in the SQL query. Below there are a number of different fields that were useful in using this type of date selection rather than a parameter. Basically if a report has a known schedule or known run dates, we can use formulas to create the date parameterd and use the created date parameters in Select Editor to select the correct records.
EndDate - Date To Use; This selects the end date, based on the month of the current month. The ‘00’ is a formating item, used with the ToText? to specify the length and also to pad with leading zeros if they are not there IE - 1 will be 01, 2 will be 02, etc.
// quarterly months
// JSF - 9/4/2009; Modified this report to remove parameters. Having the parameters made it necessary
// to schedule this report and supply the parameters rather than have a set schedule where the
// date parameters are based on the run date. this will allow the report to have a set schedule and
// be able to supply the date parameters itself without requiring the scheduler to supply these.
IF Month(CurrentDate) - 1 = 3
then ToText(31,‘00’)
else
IF Month(CurrentDate) - 1 = 6
then ToText(30,‘00’)
else
IF Month(CurrentDate) - 1 = 9
then ToText(30,‘00’)
else…
· EndDate - MDY; this concatenates the Month, date and year of the EndDate? to provide the total parameter that the date range is based on. The three fields are concatenated with the &"-"& string. Formatting (Including the zero padding) of the individual fields is done at the field level rather than in this concatenating field.
{@EndDate - YearToUse}&"-"&{@EndDate - Month}&"-"&{@EndDate - DateToUse}
· EndDate - Month; provides the end of Quarter month. Since this report runs on the 5th day of the month after the end of the quarter, the EndDate? - month is the current month minus 1 month…presuming that this report runs in April (for Jan-March), July (for April-June), October (For July-Sept.) and Jan (for Octover-December) this quarterly formula works.
ToText(month(CurrentDate)-1,‘00’)
· EndDate - YearToUse;
If Month (CurrentDate) = 1
then ToText(Year(CurrentDate)-1,’####’)
else ToText(Year(CurrentDate),’####’)
EndDate - Date To Use; This selects the end date, based on the month of the current month. The ‘00’ is a formating item, used with the ToText to specify the length and also to pad with leading zeros if they are not there IE - 1 will be 01, 2 will be 02, etc.
StartDate? formula fields
· StartDate - DateToUse?
ToText(01,‘00’)
· StartDate - MDY
({@StartDate - YearToUse})&"-"&({@StartDate - Month})&"-"&({@StartDate - DateToUse})
· StartDate - Month
ToText(month(CurrentDate)-3,‘00’)
· StartDate - YearToUse?
If Month (CurrentDate) = 1
then
ToText(Year(CurrentDate)-1,’####’)
else
ToText(Year(CurrentDate),’####’)
Once these fields are done, then what?
Remove the parameters from the command. The report will use the Selection Expert to do the date
comparison rather than the command. This will allow you to use the concatenated fields in the
selection and remove the parameters used in the command. Alter the command to feed the date
jfuhrman (BOB member since 2011-02-23)