View previous topic :: View next topic
|
Author |
Message |
narasridhar
New User
Joined: 12 Oct 2006 Posts: 32 Location: India
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
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 |
|
|
narasridhar
New User
Joined: 12 Oct 2006 Posts: 32 Location: India
|
|
|
|
Yes but i need to do this through query.... |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
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
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 |
|
|
stodolas
Active Member
Joined: 13 Jun 2007 Posts: 632 Location: Wisconsin
|
|
|
|
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 |
|
|
|