In a message dated 00-01-25 17:38:31 EST, you write:
I need your advice on the following issue:- The user should be prompted to enter year and month. The report should display the revenue for the past 12 months from the month year entered.
Steve:
What database are you using?
If Oracle, you could build a prompt that looks something like this:
months_between(trunc(some_database_date,‘MM’), to_date(@prompt(‘Enter year YYYY’,‘N’,) || @prompt(‘Enter Month MM’,‘N’,) || ‘01’ ,‘YYYYMMDD’) between -12 and 0
The months_between calculation returns the number of months between two dates. The trunc(some_database_date,‘MM’) returns the first day of the month that includes “some_database_date”. The prompt for year and month is concatenated into a string and then converted into a date for use in the months_between function.
If the database date is this month, then the months_between returns zero.
If the database date is last month, then the months_between returns -1.
If the database date is next month, then the months_between returns +1.
By using a range from -12 to 0 you should be able to return the prior 12 months.
Note: by using -12 to 0, the prompted month is included. If you want strictly the prior 12 months use -12 to -1. If you want the prior 11 months and the prompted month use -11 to 0 to get a true 12 month range.
Regards,
Dave Rathbun
Integra Solutions
www.islink.com
Listserv Archives (BOB member since 2002-06-25)