an approach

D

db2guy

i am working on db2 and need a perl script to delete data from a
table. There is a column in that table X lets say Xdate. Now i want to
keep only 90 days of data and delete everything else. The Xdate is in
timestamp format so its creating problems for me. ex
2004-03-31-00.00.00 so when i do current timestamp - 90 days the
problem is coming with time part of timestamp.
Can anyone suggest me a way.
Also how can i put this values
db2 "select count(*) from tableX" into a variable say $DD...
any suggestion will be appriciated thanks...
 
C

ctcgag

i am working on db2 and need a perl script to delete data from a
table. There is a column in that table X lets say Xdate. Now i want to
keep only 90 days of data and delete everything else. The Xdate is in
timestamp format so its creating problems for me. ex
2004-03-31-00.00.00 so when i do current timestamp - 90 days the
problem is coming with time part of timestamp.
Can anyone suggest me a way.
Also how can i put this values
db2 "select count(*) from tableX" into a variable say $DD...
any suggestion will be appriciated thanks...

While it may possible to solve this problem with Perl, the proper way
to solve it is almost surely within DB2 itself.

Xho
 
G

gnari

db2guy said:
i am working on db2 and need a perl script to delete data from a
table. There is a column in that table X lets say Xdate. Now i want to
keep only 90 days of data and delete everything else. The Xdate is in
timestamp format so its creating problems for me. ex
2004-03-31-00.00.00 so when i do current timestamp - 90 days the
problem is coming with time part of timestamp.
Can anyone suggest me a way.

I'll assume you know about DBI
I do not know about DB2's date functions, but surely there are
some that return the date part of a datestamp, or you can cast
(current day - 90 days) as timestamp or something.
In any case, surely you can do something like
$sth=$dbh->do("delete from foo where Xdate < 2004-05-16-00.00.00");

Also how can i put this values
db2 "select count(*) from tableX" into a variable say $DD...
any suggestion will be appriciated thanks...

oh. maybe you do not know about DBI.
take a look at cpan.org

you will need the modules DBI and DBD::DB2

gnari
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,159
Messages
2,570,880
Members
47,417
Latest member
DarrenGaun

Latest Threads

Top