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

Help required on writing a DB2 Query


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
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
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

Moderator Emeritus


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

PostPosted: Mon Jul 23, 2007 4:21 am
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
Reply with quote

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

Moderator Emeritus


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

PostPosted: Mon Jul 23, 2007 7:57 pm
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
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 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 Two input files & writing counter... DFSORT/ICETOOL 12
No new posts Query on edit primary command CLIST & REXX 5
No new posts Query on edit primary command CLIST & REXX 1
Search our Forums:

Back to Top