Easiest way to copy data from one table to another table?
-
28-04-2021 - |
Pregunta
After grabbing result, what is the easiest way to grab certain fields from #result and put them into a different table (the data types might not match, which will require some conversions).
select * into #result from table1
Can I do a "SELECT * INTO" or maybe a cursor to loop through #result and insert it into the destination table? Is there an even better way?
Solución
One way (if supported by the database in question) is to use an INSERT
statement with a SELECT clause. For example:
INSERT INTO targettable (val1, val2)
SELECT someval1, someval2 FROM sourcetable
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow