• CURSORS and WHILE LOOPS are both generally bad, if you're tuning your query then maybe you should look at a more set-based approach?

    If you provide readily consumable sample data, DDL scripts, the current code in your sproc and your expected result-set based on your sample data then I'm sure there will be a way to make your code perform much much better.

    Please read this article[/url] about the best way to provide us with readily consumable sample data and DDL scripts, which will allow the unpaid volunteers of this site to provide you with working, tested code that fulfils your requirements.

    Thanks.


    Forever trying to learn
    My blog - http://www.cadavre.co.uk/
    For better, quicker answers on T-SQL questions, click on the following...http://www.sqlservercentral.com/articles/Best+Practices/61537/
    For better, quicker answers on SQL Server performance related questions, click on the following...http://www.sqlservercentral.com/articles/SQLServerCentral/66909/