Create Procedure DontUseCursors As DECLARE @MasterRef varchar(10) DECLARE @ClaimRef varchar(10) Declare @i int SELECT @MasterRef = c.MasterRef, @ClaimRef = p.ClaimRef FROM PIFTest p Inner Join claim c on c.ClaimRef = p.ClaimRef INNER JOIN (SELECT MIN(ClaimRef) AS ClaimRef FROM PIFTest) Tbl1 ON p.ClaimRef = Tbl1.ClaimRef Select @i = Count(ClaimRef) From PIFTest WHILE (@i > 0) BEGIN print @ClaimRef SELECT @MasterRef = c.MasterRef, @ClaimRef = p.ClaimRef FROM PIFTest p Inner Join claim c on c.ClaimRef = p.ClaimRef INNER JOIN (SELECT MIN(ClaimRef) As ClaimRef FROM PIFTest Where ClaimRef > @ClaimRef) Tbl1 ON p.ClaimRef = Tbl1.ClaimRef print @i Set @i = (@i - 1) END GOIn this example I'm only printing out the variable, if I leave the While condition as "While @ClaimRef is not null" it just loops so I changed it to what you see ( which is not exactly elegant - but it works ) it seems @ClaimRef is never null - thanks