There are ways of inserting data into table:
insert into MyTable (ColA, ColB, ColC) values ('A', 'B', 'C')
insert into MyTable (ColA, ColB, ColC) select colAA, colBB, colCC from MyTable2
Is there way to use insert into MyTable (ColA, ColB, ColC) select colAA, colBB, colCC from MyTable2
but instead of inserting for example colAA value into colA I woulkd like to insert there always 1.
THanks for help
You can use a select-statement within an INSERT statement to insert zero, one, or more rows into a table from the result table of the select-statement. The select-statement embedded in the INSERT statement is no different from the select-statement you use to retrieve data.
INTO' creates the destination table, it exclusively owns that table and is quicker compared to the 'INSERT … SELECT'. Because the 'INSERT … SELECT' inserts data into an existing table, it is slower and requires more resources due to the higher number of logical reads and greater transaction log usage.
INSERT INTO SELECT inserts into an existing table. SELECT INTO creates a new table and puts the data in it.
Just add a constant into the SELECT
list
INSERT INTO MyTable
(ColA,
ColB,
ColC)
SELECT 1,
colBB,
colCC
FROM MyTable2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With