DECLARE @ID AS INT; SET @ID = (SELECT MIN(ID) from TABLE); WHILE @ID IS NOT NULL BEGIN PRINT @ID; SET @ID = (SELECT MIN(ID) FROM TABLE WHERE ID > @ID); END