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 Join in SQL Query vickey_dw DB2 2 Tue Jan 17, 2017 12:15 am
This topic is locked: you cannot edit posts or make replies. MQ setup query mohitsaini Java & MQSeries 4 Sun Jan 08, 2017 1:53 am
No new posts DB2 query Using Recursion, Converting... smilewithashu2 DB2 1 Tue Jan 03, 2017 12:50 pm
No new posts SQL query to run through list of valu... Ni3-db2 DB2 14 Wed Dec 14, 2016 9:52 am
This topic is locked: you cannot edit posts or make replies. Db2 SQL query to convert rows into co... subratarec DB2 5 Thu Nov 17, 2016 4:51 pm


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