T-SQLpowered

WHILE

Iterate with MIN/MAX Id. Doesn’t perform well for broken number sequences.

DECLARE @Current_Id INT
DECLARE @Max_Id INT
DECLARE @Ids TABLE ( [Id] INT)

INSERT INTO @Ids ([Id])
	SELECT [Id]
	FROM (VALUES (1),(2),(3)) [v] ([Id])

SELECT @Current_Id = MIN([Id]) FROM @Ids
SELECT @Max_Id = MAX([Id]) FROM @Ids

WHILE @Current_Id <= @Max_Id
BEGIN

    SELECT 
		@Current_Id = [Id]
    FROM @Ids
    WHERE [Id] = @Current_Id

    PRINT @Current_Id

    SET @Current_Id = @Current_Id + 1

END
GO