• You have a few options here. The first thing is that a query like this maybe impacted by bad parameter sniffing so test it with and without recompile.

    1. Set @value = nullif(@value,'ALL') ... Location = coalesce(@value,Location) -- This should have at least statement level recompile

    2. Dynamic SQL if @value <> 'ALL' set @whereStmt = N' where Location = @value '

    There are a lot of different options actually, but I would consider the first two and see how performance is afterwards.



    Microsoft Certified Master - SQL Server 2008
    Follow me on twitter: @keith_tate

    Forum Etiquette: How to post data/code on a forum to get the best help[/url]