Link to home
Start Free TrialLog in
Avatar of Axter
AxterFlag for United States of America

asked on

insert partial existing row data and fixed values into table

I'm trying to insert some existing row values, but with having some of the fields of different value.

I have the below code, which is of course giving syntax error, but I'm not sure how to fix it.
Can someone please point me in right direction?

Thanks
insert into TableFooFoo 
(column1, column2, column3, column4, columnGettingNewValue1, columnGettingNewValue2, columnGettingNewValue3)
 (
select column1, column2, column3, column4 from TableFooFoo where columnGettingNewValue3 = 'foo1' 
UNION 123, 'NewValue2', 'NewFoo'
);

Open in new window

Avatar of j-horb
j-horb

UPDATE TableFooFoo Set Column1=123,Column2='NewValue2',Column3='NewFoo' WHERE column3 = 'fool'

(or WHERE columnGettingNewValue3 ='fool' depending what the table structure is)

in short, you need to use UPDATE rather than INSERT, if I'm reading your question correctly
Avatar of Axter

ASKER

By I don't want to change the existing row, and instead I want to insert a copy of the row, with some fields being different.

I also need a way to put the existing row value together with new field values.
ASKER CERTIFIED SOLUTION
Avatar of j-horb
j-horb

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Axter

ASKER

Thank you very much.  That's what I'm looking for.