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
 
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 HEX value search in a DB2 query maxsubrat DB2 2 Wed Oct 04, 2017 3:04 pm
No new posts Create procedure issues -628 when add... chandraBE DB2 1 Mon Sep 18, 2017 12:16 pm
No new posts Can we limit length in concatenation ... balaji81_k DB2 7 Tue Aug 22, 2017 2:50 am
No new posts Writing a file using online program grvtomar PL/I & Assembler 3 Fri Jun 30, 2017 1:06 pm
No new posts Need DB2 query to fetch previous row ! Chandan1993 DB2 10 Sat Jun 03, 2017 10:43 am

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