Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Query changes from weekly report to monthly report

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
View previous topic :: :: View next topic  
Author Message
chandracdac

New User


Joined: 15 Jun 2007
Posts: 92
Location: bangalore

PostPosted: Fri Nov 16, 2007 7:07 pm    Post subject: Query changes from weekly report to monthly report
Reply with quote

Hi, I am having issue with DB2 Query.

Currently my job is running weekly and generating report for a week. The existing query is like this

SELECT aaa_timestamp,bbb,ccc FROM xyz WHERE DATE (aaa_timestamp) BETWEEN (CURRENT DATE-6 DAYS) AND (CURRENT DATE)

Now i have to modify to monthly job and i have to generate report for the last entire month.
Since the query has been hard coded directly inside a jcl. So we have to specify all the conditions in a single query.

[Note: We have to take care that every month having different days and also leap year]

could please any one suggest for this, its urgent.
Back to top
View user's profile Send private message

Craq Giegerich

Senior Member


Joined: 19 May 2007
Posts: 1512
Location: Virginia, USA

PostPosted: Fri Nov 16, 2007 7:33 pm    Post subject: Re: Query changes from weekly report to monthly report
Reply with quote

chandracdac wrote:
Hi, I am having issue with DB2 Query.

Currently my job is running weekly and generating report for a week. The existing query is like this

SELECT aaa_timestamp,bbb,ccc FROM xyz WHERE DATE (aaa_timestamp) BETWEEN (CURRENT DATE-6 DAYS) AND (CURRENT DATE)

Now i have to modify to monthly job and i have to generate report for the last entire month.
Since the query has been hard coded directly inside a jcl. So we have to specify all the conditions in a single query.

[Note: We have to take care that every month having different days and also leap year]

could please any one suggest for this, its urgent.

Code:
WHERE DATE (aaa_timestamp) BETWEEN  (CURRENT DATE- DAY(CURRENT DATE) DAYS + 1 DAYS) AND  (CURRENT DATE)

WARNING: If the query is not run on the last day of the month (ie. your system is down and you don't get to run it until the next day) you will get incorrect results.
Back to top
View user's profile Send private message
enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10274
Location: italy

PostPosted: Fri Nov 16, 2007 7:50 pm    Post subject: Reply to: Query changes from weekly report to monthly report
Reply with quote

Quote:
SELECT aaa_timestamp,bbb,ccc FROM xyz WHERE DATE (aaa_timestamp) BETWEEN (CURRENT DATE-6 DAYS) AND (CURRENT DATE)


the query does NOT satisfy correctly the Business objectives for weekly/monthly reporting

a better way of approaching the business requirement for a weekly report
would be

Quote:
SELECT needed_columns FROM table
WHERE date BETWEEN first_date_of_the_period AND last_date_of_the_period


where beforehand the first date and the last date have been determined
thru a business calendar,

this approach will have the advantage of making the query independent from the run day
- quite advisable with automated scheduling,
if the query has to run after a batch process running in the evening,
a delay in the predecessors will cause Your query to run the following day
giving inconsistent results

/rant on
something that still amazes me after many year of IT consulting
is how hard is to make organizations understand and act in the right way
on calendar related issues
/rant off
Back to top
View user's profile Send private message
Craq Giegerich

Senior Member


Joined: 19 May 2007
Posts: 1512
Location: Virginia, USA

PostPosted: Fri Nov 16, 2007 8:44 pm    Post subject:
Reply with quote

1. They are switching from weekly to monthly. The query the op posted would get the last weeks worth of data, not necessarily a calendar week.

2. I missed the "last complete month" part so to correct that use:
Code:
WHERE DATE (aaa_timestamp) BETWEEN  (CURRENT DATE - DAY (CURRENT DATE) DAYS  - DAY((CURRENT DATE) - DAY(CURRENT DATE)DAYS) DAYS
    + 1 DAYS) AND  (CURRENT DATE - DAY(CURRENT DATE) DAYS)

Messy but it works.
Back to top
View user's profile Send private message
senthilkuduva

New User


Joined: 16 Nov 2007
Posts: 2
Location: chennai

PostPosted: Sat Nov 17, 2007 8:36 am    Post subject: Re: Reply to: Query changes from weekly report to monthly re
Reply with quote

Hi, I am also working on the same problem, Here we cant simply mention like between first day and last day of month because,

If it is running on jan 1st then has to generate report for dec which is having31 days

If it is running on mar 1st then has to generate report for feb which is having 28 days and for leap year 29 days


If it is running on May 1st then has to generate report for APr which is having30 days

Please suggest query for this.
Back to top
View user's profile Send private message
chandracdac

New User


Joined: 15 Jun 2007
Posts: 92
Location: bangalore

PostPosted: Sat Nov 17, 2007 9:16 am    Post subject: Reply to: Query changes from weekly report to monthly report
Reply with quote

Thanks to all
Back to top
View user's profile Send private message
chandracdac

New User


Joined: 15 Jun 2007
Posts: 92
Location: bangalore

PostPosted: Sat Nov 17, 2007 9:23 am    Post subject: Reply to: Query changes from weekly report to monthly report
Reply with quote

Thanks craq its working..
Back to top
View user's profile Send private message
senthilkuduva

New User


Joined: 16 Nov 2007
Posts: 2
Location: chennai

PostPosted: Sat Nov 17, 2007 11:54 am    Post subject: Re: Reply to: Query changes from weekly report to monthly re
Reply with quote

Hi Craq Giegerich,

Thank you very much. Your query is working fine
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Report cost in CA-dispatch Nileshkul CA Products 3 Wed Jun 07, 2017 10:32 pm
No new posts Need DB2 query to fetch previous row ! Chandan1993 DB2 10 Sat Jun 03, 2017 10:43 am
No new posts Splitting of single report to seperat... abdulrafi TSO/ISPF 7 Mon Mar 27, 2017 3:59 pm
No new posts JCL to Set Return code based on DB2 S... vinu78 DB2 17 Mon Mar 13, 2017 9:47 pm
No new posts Easytrieve report shalem CA Products 4 Sun Feb 26, 2017 9:08 am


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us