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 reg query on DYNALLOC feature raghuraman123 SYNCSORT 12 Wed Jan 10, 2018 2:42 pm
No new posts query to fetch record which has only ... maxsubrat DB2 12 Mon Dec 11, 2017 5:03 pm
No new posts How to query MAXGENS of an existing P... Chuchulo Hatyzak JCL & VSAM 4 Wed Nov 22, 2017 10:23 pm
No new posts Native SQL Query kishpra DB2 1 Wed Nov 22, 2017 8:38 pm
No new posts Query on IEFBR14 with GDG Ashishpanpaliya JCL & VSAM 4 Tue Nov 07, 2017 8:34 pm

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