• Thank u,

    in 99 percent cases, i use set based approach , this was quite old situation , so i was forced to use loop.

    but my question was to have that extra select or not. the script u have posted is

    INSERT INTO #Tmp1(Tmp1, brId, sdate)

    SELECT ROW_NUMBER() OVER(ORDER BY sdate, brId), brId, sdate

    FROM #sd;

    so i am taking it in this way , that my rows will have unique sequqntial(with out gap) numbers ( order by sdate and brid ) so that i can use Tmp1

    to loop in sequential manner

    or to show reports from #tmp1 using order by tmp1 rather than (sdate and brid)

    your sincerely