简体   繁体   中英

Looping through list of values and inserting

I have a select that returns employee IDs of type int. I'd like to use these empId values as part of an insert. Basically, I need to loop through all IDs, inserting them. But how is that does done?

I know a cursor can be used for this scenario but isn't there a way to do it without the cursor?

INSERT INTO 
  table2 
( 
 employeeID 
)
SELECT
  employeeID
FROM
  table1

You can do:

INSERT INTO SomeTable
(Column1, Column2, Column3)
SELECT ColumnA, ColumnB, ColumnC
FROM OtherTable
WHERE ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM