• Without looking at details/specifics,

    you can try to get a 'blind' performance gain by using @Table table type variable instead of

    #temporary table. You can gain performance improvement to some extent by avoiding writing/reading to/form disk

    because table type variable is processed in memory. But with a large number of rows it may present another problem,

    depending on how much available memory your server has and you do need to look ant the query exec plan, no doubt.

    Likes to play Chess