Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 9164

Re: Date for Month year only?

$
0
0

I would create a command (SQL Select statement) to use for data for a dynamic prompt.  It might look something like this in Oracle (allows for two full calendar years in the past):

 

Select distinct

To_Char(OrderDate, 'MMM-YYYY')  as MonthYear

from Orders

where EXTRACT(Year from OrderDate) >= (EXTRACT(Year from Sysdate) - 2)

 

 

Or like this in SQL Server:

 

Select distinct

Left(DateName(month, OrderDate), 3) + '-' + DateName(year, OrderDate) as MonthYear

from Orders

where Year(OrderDate) >= (Year(GetDate()) - 2)

 

DO NOT link the command to anything in the report - its sole purpose is to provide data for a dynamic prompt.  Crystal will complain that this is generally not supported, but it will work in this situation.

 

Now create a dynamic parameter that will use this data - DO NOT use any other data from your report tables!  This parameter will identify the start month for the report.

 

Lastly, you'll need to create a two formulas - one that will calculate the start date from the parameter value and another that will create the end date.  If the parameter is called {?StartMonth}, they might look like this:

 

{@StartDate}

StringVar monthName := UpperCase(Left({?StartMonth}, 3));

 

//get the month number

NumberVar mn := Switch (

  monthName = 'JAN', 1,

  monthName = 'FEB', 2,

  ...

  monthName = 'DEC', 12);

 

//get the Year number

NumberVar yr := ToNumber(Right({?StartMonth}, 4));

 

//return the first day of the start month:

Date(yr, mn, 1)

 

{@EndDate}

//Subtract one day from the start of the month 2 months after the start date to get the end of the

//month after the start date

DateAdd('m', 2, {@StartDate})  -  1 

 

Use these formulas in your selection criteria for your report.

 

-Dell


Viewing all articles
Browse latest Browse all 9164

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>