If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Purging of data in db2 tables

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-02-07, 13:31
chaitu_onweb chaitu_onweb is offline
Registered User
 
Join Date: Dec 2006
Posts: 6
Purging of data in db2 tables

Hi all,

I am writing a script to purge (remove) data which is 30 days old than
the present date. Now how do i develop this script in such a way that
it runs in crontab. I have used the statement like


db2 "delete from orders21 where order_time <
'2006-12-01-06.53.46.000000'".


Now is there a statement like


db2 "delete from orders21 where order_time <
'date-2006-12-01-06.53.46.000000'". Where date is present day date.


And is there a way to print the date in the same format
(2006-12-01-06.53.46.000000)? Because when we print date in UNIX it
gives the following format.


Tue Jan 2 11:03:57 EST 2007.


I have also seen this format in groups google


delete from orders21 where (today - order_time) > interval '30' day .


It hasn't worked for me.


Thanks in advance,


Chaitanya
Reply With Quote
  #2 (permalink)  
Old 01-02-07, 14:02
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
Well assuming that the "ORDER_TIME" column is a timestamp, this should work:

DELETE from orders21 where ordertime < (current timestamp - 30 days)

HTH

Andy
Reply With Quote
  #3 (permalink)  
Old 01-02-07, 14:43
chaitu_onweb chaitu_onweb is offline
Registered User
 
Join Date: Dec 2006
Posts: 6
wow Andy,

awesome. Thanks a lot.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On