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

delete from a table


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

New User


Joined: 11 Nov 2008
Posts: 11
Location: Pune

PostPosted: Mon Jul 12, 2010 12:32 pm
Reply with quote

Hello,

I have two tables 1) log table 2) user table

log table is having user id ,actvty_timestamp
and user table is having user id and retention days as column

my job is to delete the records from log table if the following condition
satisfies

1)current timestamp - actvty_timestamp > retention days
2)and userid should match of both the tables

I have written the following query but it is not working fine.

DELETE FROM SDAUDLOG A WHERE A.USER_ID IN
(SELECT A.USER_ID
FROM DEVSQL3.COMISDFT B,DEVSQL3.SDAUDLOG A
WHERE B.USERID=A.USER_ID
AND (DAY(CURRENT_TIMESTAMP)-DAY(A.ACTVTY_TS))>B.ACTV_LOG_RETN_DYS );

it is deleting all the records related to the userid .But i don't want to delete all the records.I have to delete the records satisfying the two conditions only

please suggest.Thanks.
Back to top
View user's profile Send private message
cdhami

New User


Joined: 24 Jan 2006
Posts: 28

PostPosted: Mon Jul 12, 2010 1:08 pm
Reply with quote

Hi Aishvarya,
it is deleting records related to user id because you are putting a check only on the matched user id before delete.

I suggest to use a existence check instead of subquery which will satisfy your requirement.


Hope this helps.
cdhami
Back to top
View user's profile Send private message
GuyC

Senior Member


Joined: 11 Aug 2009
Posts: 1281
Location: Belgium

PostPosted: Mon Jul 12, 2010 1:10 pm
Reply with quote

Code:
DELETE FROM SDAUDLOG A
WHERE A.ACTVTY_TS < (select current_timestamp - B.ACTV_LOG_RETN_DYS  Days from  DEVSQL3.COMISDFT B WHERE B.USERID=A.USER_ID)
Back to top
View user's profile Send private message
aishvarya_82

New User


Joined: 11 Nov 2008
Posts: 11
Location: Pune

PostPosted: Wed Jul 21, 2010 9:06 pm
Reply with quote

Hi ,

Sorry for the late reply.

The query is running fine now as answered in this post.
Thank you very much

Thanks
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 DELETE SPUFI DB2 1
No new posts Load new table with Old unload - DB2 DB2 6
No new posts DSNTIAUL driven delete IBM Tools 0
No new posts Pulling a fixed number of records fro... DB2 2
No new posts Multiple table unload using INZUTILB DB2 2
Search our Forums:

Back to Top