MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Cobol Delete Rows Where Timestamp > 60 days old

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database
View previous topic :: View next topic  
Author Message
ROBERTLa
Beginner


Joined: 07 Dec 2003
Posts: 8
Topics: 5

PostPosted: Sun Dec 07, 2003 7:21 am    Post subject: Cobol Delete Rows Where Timestamp > 60 days old Reply with quote

Gents:

What's the best way to code Cobol-SQL to delete all rows where Timestamp (ccyy-mm-dd part only) > 60 days old ?

I understand that timestamps have a special internal DB2 format (which apperently includes the hyphens) and Cobol has no timestamp data-type as such.

I'd like to use the timestamp in the SQL where block (ie: make the timestamp an indexed value) to be able to do mass deletes based on its value. Do you see any issues with that ?

Robert
Back to top
View user's profile Send private message
sriramla
Beginner


Joined: 22 Feb 2003
Posts: 74
Topics: 1

PostPosted: Sun Dec 07, 2003 11:36 pm    Post subject: Reply with quote

EXEC SQL
DELETE FROM <Tabe>
WHERE col1 + 60 DAYS < CURRENT DATE
END-EXEC
DISPLAY SQLERRD(3) --> To know how many records have been deleted.
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12401
Topics: 75
Location: San Jose

PostPosted: Mon Dec 08, 2003 6:17 am    Post subject: Reply with quote

Robetla,

Sriramla has the right idea but his syntax is wrong.Robert has the column in a timestamp format.You don't really need cobol code for your case.you can code a simple sql statement shown below to delete all the rows which are are 60 days old.

Code:

DELETE FROM TABLE                                                       
   WHERE DATE(T_STMP_COL) < (SELECT DATE(CURRENT DATE - 60 DAYS)   
                             FROM SYSIBM.SYSDUMMY1)                 
   ;                                                               


Hope this helps...

cheers

kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
sriramla
Beginner


Joined: 22 Feb 2003
Posts: 74
Topics: 1

PostPosted: Mon Dec 08, 2003 7:16 am    Post subject: Reply with quote

Kolusu, You are right. The syntax is not correct. Anyway, you got the idea. Instead of col1 + 60 days < current date, we can use DATE(col1) + 60 days < current date. This will work. (This time, I've done some home work on syntax before writing this..)
Back to top
View user's profile Send private message
SureshKumar
Intermediate


Joined: 23 Jan 2003
Posts: 211
Topics: 21

PostPosted: Mon Dec 08, 2003 9:58 am    Post subject: Reply with quote

Kolusu, Just for clarification - what was the reason behind using a sub-query ? will it not suffice to use just the date function ? like
DELETE FROM TABLE
WHERE DATE(T_STMP_COL) < DATE(CURRENT DATE - 60 DAYS)
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12401
Topics: 75
Location: San Jose

PostPosted: Mon Dec 08, 2003 10:23 am    Post subject: Reply with quote

Sureshkumar,

The query you have shown without the use of subquery works with DB2 version 7 and higher. I am not sure that every shop has upgraded the latest version of DB2. My query works for DB2 v5 and higher. I am assuming that most shops will have atleast version 5 of db2 as DB2 V4 is an unsupported version from DB2.

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group