SQLTeam.com | Weblogs | Forums

Is it possible to insert columns from one table to another plus hard coded values

sql2008

#1

i now need to insert columns from one table to another, but also hard code some values to the receiving table.

this is what is needed but it failed 'Keyword INSERT not expected.' on the second insert statement

INSERT INTO CA1665AFTT.EMODESADV3
(E3ecsn, e3mena, e3hand)
VALUES ('333', 'EDI400', 'MR1');

INSERT INTO CA1665AFTT.EMODESADV3
(E3CPRD, E3CQTY)
SELECT prdc, oqty
FROM Monica.emod


#2

Sure, why not?INSERT INTO CA1665AFTT.EMODESADV3 (E3CPRD, E3CQTY, E3ecsn, e3mena, e3hand) SELECT prdc, oqty, '333', 'EDI400', 'MR1' FROM Monica.emodI'm not sure if this is what you wanted. It does insert the constants into every row selected. In general, if you can SELECT the values, either as a table column or a constant or an expression, etc., you can insert it into the target table.


#3

yes that is it! Thanks!