Tambahkan identitas ke variabel tabel Anda, dan lakukan loop mudah dari 1 ke @@ROWCOUNT dari INSERT-SELECT.
Coba ini:
DECLARE @RowsToProcess int
DECLARE @CurrentRow int
DECLARE @SelectCol1 int
DECLARE @table1 TABLE (RowID int not null primary key identity(1,1), col1 int )
INSERT into @table1 (col1) SELECT col1 FROM table2
SET @[email protected]@ROWCOUNT
SET @CurrentRow=0
WHILE @CurrentRow<@RowsToProcess
BEGIN
SET @[email protected]+1
SELECT
@SelectCol1=col1
FROM @table1
WHERE [email protected]
--do your thing here--
END