Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Regarding the Query..

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
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    Post subject: Regarding the Query..
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    Post subject: Re: Regarding the Query..
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    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 JCL to Set Return code based on DB2 S... vinu78 DB2 17 Mon Mar 13, 2017 9:47 pm
No new posts SQL query not working in Cobol program. CuriousMainframer COBOL Programming 14 Wed Feb 22, 2017 5:56 pm
No new posts Omegamon for DB2 query ashek15 DB2 0 Wed Feb 15, 2017 11:25 am
No new posts Query on DB2 WLM stored procedures ashek15 DB2 8 Sun Feb 12, 2017 11:13 pm
No new posts GETMAIN/FREEMAIN query Suja.Sai CICS 9 Tue Jan 31, 2017 12:01 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us