[英]Looping through list of values and inserting
I have a select that returns employee IDs of type int. 我有一个选择返回int类型的员工ID。 I'd like to use these empId values as part of an insert. 我想将这些empId值用作插入的一部分。 Basically, I need to loop through all IDs, inserting them. 基本上,我需要遍历所有ID,然后插入它们。 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 ...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.