• Again, if you really need to loop you can do so without temp table.

    DECLARE MyCurs CURSOR LOCAL FAST_FORWARD

    FOR SELECT brId, sdate

    FROM Somewhere

    ORDER BY sdate, brId;


    Hugo Kornelis, SQL Server/Data Platform MVP (2006-2016)
    Visit my SQL Server blog: https://sqlserverfast.com/blog/
    SQL Server Execution Plan Reference: https://sqlserverfast.com/epr/