Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
Need query for mentioned req

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
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    Post subject: Need query for mentioned req
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    Post subject:
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    Post subject:
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    Post subject:
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    Post subject:
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    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts HEX value search in a DB2 query maxsubrat DB2 2 Wed Oct 04, 2017 3:04 pm
No new posts Create procedure issues -628 when add... chandraBE DB2 1 Mon Sep 18, 2017 12:16 pm
No new posts Can we limit length in concatenation ... balaji81_k DB2 7 Tue Aug 22, 2017 2:50 am
No new posts Need DB2 query to fetch previous row ! Chandan1993 DB2 10 Sat Jun 03, 2017 10:43 am
No new posts JCL to Set Return code based on DB2 S... vinu78 DB2 17 Mon Mar 13, 2017 9:47 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us