IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Need a job to extract monthly data from db2 table


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
shakti

New User


Joined: 20 Jan 2004
Posts: 42

PostPosted: Tue Apr 22, 2008 4:19 pm
Reply with quote

My job is scheduled on last date of every month and this job would retrieve the current month's data from the DB2 table. Could you plesse let me know how retrieval is possible.

Sakthi
Back to top
View user's profile Send private message
the_gautam

Active User


Joined: 05 Jun 2005
Posts: 165
Location: Bangalore

PostPosted: Tue Apr 22, 2008 4:40 pm
Reply with quote

what is the structure of the DB2 table?
you can retrieve the data easily if the table is containing any date or timestamp field.
Back to top
View user's profile Send private message
vasanthkumarhb

Active User


Joined: 06 Sep 2007
Posts: 275
Location: Bang,iflex

PostPosted: Tue Apr 22, 2008 4:48 pm
Reply with quote

Hi,

If you have month entity in your table you can do it as below.


Code:
SELECT var1, var2, var3, var4,month
FROM TABLE
WHERE month = 'march'
GROUP BY var1,var2,month,var3,var4;
Back to top
View user's profile Send private message
shakti

New User


Joined: 20 Jan 2004
Posts: 42

PostPosted: Wed Apr 23, 2008 10:46 am
Reply with quote

Hi Gautam,

Thanks for the clarification.

Regarding your query, I have a table with timestamp as one of the column.

Could you please let me know how the retrival query could be?

Thanks in advance.

Shakti
Back to top
View user's profile Send private message
vasanthkumarhb

Active User


Joined: 06 Sep 2007
Posts: 275
Location: Bang,iflex

PostPosted: Wed Apr 23, 2008 12:45 pm
Reply with quote

Hi,

the variable contain the TIMESTAMP value which constitute date as well as time up to microseconds.

you take the substring of the timestamp to compare in the query to get the complete last month data.

check this query and try.


Code:
SELECT * FROM my_table WHERE SUBSTRING(timestamp_val,1,8) = DATE '2002-10-03';
Back to top
View user's profile Send private message
Prajesh_v_p

Active User


Joined: 24 May 2006
Posts: 133
Location: India

PostPosted: Wed Apr 23, 2008 1:26 pm
Reply with quote

If I understand your requirement currectly, Will not the below solution work?

WHERE MONTH(timestamp_val) = MONTH(CURRENT DATE)

Thanks,
Prajesh
Back to top
View user's profile Send private message
the_gautam

Active User


Joined: 05 Jun 2005
Posts: 165
Location: Bangalore

PostPosted: Wed Apr 23, 2008 1:41 pm
Reply with quote

Code:
SELECT * FROM MY_TABLE WHERE MONTH(timestamp_val) = MONTH(CURRENT DATE)
Back to top
View user's profile Send private message
Bharath Bhat

Active User


Joined: 20 Mar 2008
Posts: 283
Location: chennai

PostPosted: Wed Apr 23, 2008 1:45 pm
Reply with quote

Prajesh_v_p wrote:
If I understand your requirement currectly, Will not the below solution work?

WHERE MONTH(timestamp_val) = MONTH(CURRENT DATE)

Thanks,
Prajesh

It will work Prajesh. icon_biggrin.gif
Back to top
View user's profile Send private message
Craq Giegerich

Senior Member


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

PostPosted: Wed Apr 23, 2008 5:42 pm
Reply with quote

What if there is more than 1 years worth of data in the table?


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


What will you do if the query can't be executed on the last day of the month?
What will you do if there is additional data added to the table after the query is executed and before the end of the day?
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts Store the data for fixed length COBOL Programming 1
No new posts Extract the file name from another fi... DFSORT/ICETOOL 6
No new posts Load new table with Old unload - DB2 DB2 6
No new posts Need help for File Aid JCL to extract... Compuware & Other Tools 23
No new posts Pulling a fixed number of records fro... DB2 2
Search our Forums:

Back to Top