• FWIW, imex's query will generate the same plan as yours but it's simpler to write.

    Phil's might be better or not, you'll need to test it before you implement it.

    For questions about performance, you should read the following article to ensure that you're giving all the information needed. http://www.sqlservercentral.com/articles/SQLServerCentral/66909/

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2