SQL Iteration

--Iteration and row by row in sql
--Start
DECLARE @i int
DECLARE @NarrationID int
declare @numrows int
DECLARE @Narration_table TABLE ( idx smallint Primary Key IDENTITY(1,1), NarrationID int)

-- populate employee table 
INSERT @Narration_table 
SELECT distinct NarrationID FROM NARRATION_BKP

-- enumerate the table 
SET @i = 1
SET @numrows = (SELECT COUNT(*) FROM @Narration_table)
IF @numrows > 0
    WHILE (@i <= (SELECT MAX(idx) FROM @Narration_table))
    BEGIN

        -- get the next employee primary key
        SET @NarrationID = (SELECT NarrationID FROM @Narration_table WHERE idx = @i)
        print @NarrationID
    --
        -- do something with this employee
    --
    
        -- increment counter for next employee
        SET @i = @i + 1
    END
--end