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
 

 

Help required on writing a DB2 Query

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
View previous topic :: :: View next topic  
Author Message
narasridhar

New User


Joined: 12 Oct 2006
Posts: 32
Location: India

PostPosted: Mon Jul 23, 2007 3:59 am    Post subject: Help required on writing a DB2 Query
Reply with quote

Hi,

While inserting the new row, i want to update 4 columns in the new inserted rows. Can we achieve this in the same query. WIth the below query i am getting the -803 row because the row already exist in the table. But i need the same row for all the occurences with the new common values for 4 columns for all the rows.

Please find the query which i have written.

But need to update this query to update the values for 4 columns same values for all the inserting rows.

INSERT INTO INSOUCAT.EQPT_APPEARANCE
(
SELECT * FROM INSOUCAT.EQPT_APPEARANCE A
WHERE EXISTS
(SELECT * FROM INSOUCAT.EQUIPMENT_UNIT B
WHERE A.EQAP_INTNL_ID_FK = B.EQUT_INTNL_ID
AND B.EQUT_EQPT_TYPE_FK = 'DFI')
))
;

Thanks in advance.

Thanks,
Sri.
Back to top
View user's profile Send private message

dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Mon Jul 23, 2007 4:21 am    Post subject:
Reply with quote

Hello,

I'm not sure that i understand exactly what you mean by "update 4 columns" but you might consider breaking your process into 2 pieces.

One piece would probably be a cursor to fetch the desired info. The other to make the modifications to the 4 fields and then issue the INSERT.
Back to top
View user's profile Send private message
narasridhar

New User


Joined: 12 Oct 2006
Posts: 32
Location: India

PostPosted: Mon Jul 23, 2007 7:09 pm    Post subject:
Reply with quote

Yes but i need to do this through query....
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Mon Jul 23, 2007 7:57 pm    Post subject:
Reply with quote

Hello,

What business rule says it has to be thru query?

I'd suggest you need to implement a solution that will work correctly and possibly be expanded if more conditions are identified for subsequent iterations.

Just curious, but how do you "update 4 columns" on an INSERT? They don't currently exist or it would not be an insert icon_confused.gif

For anyone here to really be of assistance, you need to clarify your requirement. If you post examples of what data currently exists and what you want to insert/update, someone may have a suggestion. Show some input rows and some "output" rows - you need post only the relevant fields.
Back to top
View user's profile Send private message
stodolas

Active Member


Joined: 13 Jun 2007
Posts: 632
Location: Wisconsin

PostPosted: Mon Jul 23, 2007 8:34 pm    Post subject:
Reply with quote

If you are doing an insert and already know that 4 fields are going to be static values and you only need a select few from your other table then only select the values you need from the other table and put your static values in the query. Enumerate your selected fields, dont' use SELECT *

Code:

INSERT INTO Table2
(SELECT Field1, Field2, Field3, 'BOB', 1, 'DBA', '2006-01-01'
FROM SourceTable)
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 Writing on to GSAM variable length rohanthengal JCL & VSAM 6 Fri Mar 03, 2017 7:46 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


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