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

Need query for mentioned req


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

New User


Joined: 15 Sep 2006
Posts: 20
Location: bangalore

PostPosted: Fri Jul 01, 2011 11:04 am
Reply with quote

Hi All,

My requirement is as below

TABLE1

*COLM1  PK
*COLM2  PK
IND

TABLE2
*COLM1  PK
*COLM2 PK
*COLM3  PK
RECORD_TIMESTAMP



I need to update TABLE1.IND as ‘1’ if
1) The Table1.IND is not an ‘1’ already
2) The Table1 has no TABLE2 records that has a record_timestamp within the last 13 months.

Can any one help me out in this.

Thanks,
Jyothi
Back to top
View user's profile Send private message
karnataka

New User


Joined: 15 Sep 2006
Posts: 20
Location: bangalore

PostPosted: Fri Jul 01, 2011 11:06 am
Reply with quote

Table description was not proper in above mail. '-->' symbol has replaced with some numeric value .. Please have a look below for correct description

TABLE1

*COLM1 --> PK
*COLM2 --> PK
IND

TABLE2
*COLM1 --> PK
*COLM2 -->PK
*COLM3 --> PK
RECORD_TIMESTAMP
Back to top
View user's profile Send private message
gylbharat

Active Member


Joined: 31 Jul 2009
Posts: 565
Location: Bangalore

PostPosted: Fri Jul 01, 2011 11:39 am
Reply with quote

Hi Jyoti,

Try this

Code:

UPDATE TABLE1
SET IND = '1'
WHERE IND <>'1'
AND (COLM1,COLM2) NOT IN (SELECT COLM1,COLM2 FROM TABLE2
                  WHERE RECORD_TIMESTAMP BETWEEN CURRENT TIMESTAMP AND (RECORD_TIMESTAMP - 13 MONTHS);


I havent tested it though....
Back to top
View user's profile Send private message
GuyC

Senior Member


Joined: 11 Aug 2009
Posts: 1281
Location: Belgium

PostPosted: Fri Jul 01, 2011 2:46 pm
Reply with quote

"IN-list" like above (a small error : it should say "current timestamp - 13 months" or
if you like performant queries use "not exists"

Code:
UPDATE TABLE1 A
SET IND = '1'
WHERE IND <>'1'
AND not exists  (SELECT 1 FROM TABLE2 B
                  WHERE a.colm1 = b.colm1 and a.colm2 = b.colm2
          and  RECORD_TIMESTAMP > (CURRENT TIMESTAMP - 13 MONTHS));
Back to top
View user's profile Send private message
gylbharat

Active Member


Joined: 31 Jul 2009
Posts: 565
Location: Bangalore

PostPosted: Fri Jul 01, 2011 3:30 pm
Reply with quote

Thanks GuyC... I just copy pasted and it went un-noticed...
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 RC query -Time column CA Products 3
No new posts Dynamically pass table name to a sele... DB2 2
No new posts Query on edit primary command CLIST & REXX 5
No new posts Query on edit primary command CLIST & REXX 1
No new posts Issue with EXEC CICS QUERY SECURITY c... CICS 6
Search our Forums:

Back to Top