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

Regarding the Query..


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

Active User


Joined: 02 Jul 2005
Posts: 124
Location: Gurgaon

PostPosted: Fri Mar 03, 2006 3:34 pm
Reply with quote

in Table-A I have 10 records, and Table-B is empty.
now I wanted to write a query like....

Wanted to select all the data from table-A, and insert into table-B. After inserting the records into table-B, I wanted to verify whether all the records have been copied or not? If counts are okay then I wanted to update the time stamp.

Right now I have written a query like below. now I wanted to add that above condition to this query.

000069 //SYSIN DD *
000070 INSERT INTO P2CE3P01.CE_ENVR
000071 (CLNT_ID, ENVR_DATA_TX, ENVR_NM, ENVR_TS, PRVS_NMBR_ID)
000072 SELECT CLNT_ID, ENVR_DATA_TX, ENVR_NM, ENVR_TS, PRVS_NMBR_ID
000073 FROM Z0CE3Z01.CE_ENVR;
000074 //*

Thanks!
CrrIndia.
Back to top
View user's profile Send private message
DavidatK

Active Member


Joined: 22 Nov 2005
Posts: 700
Location: Troy, Michigan USA

PostPosted: Sat Mar 04, 2006 12:20 am
Reply with quote

CrrIndia,

First, you need to have faith in DB2 to do what you told it to do, unless it failed.

If I wanted to copy from 1 table to another and update with CURRENT_TIMESTAMP, I would:

Code:

 INSERT INTO P2CE3P01.CE_ENVR
 (CLNT_ID,
  ENVR_DATA_TX,
  ENVR_NM,
  ENVR_TS,
  PRVS_NMBR_ID)
SELECT CLNT_ID,
       ENVR_DATA_TX,
       ENVR_NM,
       CURRENT_TIMESTAMP,
       PRVS_NMBR_ID
 FROM Z0CE3Z01.CE_ENVR
;


However, If you insist in checking the counts:

Code:

INSERT INTO P2CE3P01.CE_ENVR
 (CLNT_ID,
  ENVR_DATA_TX,
  ENVR_NM,
  ENVR_TS,
  PRVS_NMBR_ID)
SELECT CLNT_ID,
       ENVR_DATA_TX,
       ENVR_NM,
       ENVR_TS,
       PRVS_NMBR_ID
 FROM Z0CE3Z01.CE_ENVR
;
UPDATE P2CE3P01.CE_ENVR
   SET ENVR_TS = CURRENT_TIMESTAMP
 WHERE EXISTS
       (SELECT A.COUNT_A
          FROM (SELECT COUNT(*) AS COUNT_A
                  FROM Z0CE3Z01.CE_ENVR
                ) A,       
               (SELECT COUNT(*) AS COUNT_B
                  FROM P2CE3P01.CE_ENVR
                ) B
          WHERE A.COUNT_A = B.COUNT_B
        )
;


Dave
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