4thSpace
4thSpace

Reputation: 44312

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?

Upvotes: 0

Views: 181

Answers (2)

Nathanial Woolls
Nathanial Woolls

Reputation: 5291

You can do:

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

Upvotes: 0

Jake Feasel
Jake Feasel

Reputation: 16955

INSERT INTO 
  table2 
( 
 employeeID 
)
SELECT
  employeeID
FROM
  table1

Upvotes: 3

Related Questions