• The other problem with that is that when the proc compiles, all of the selects compile, based on the values of the parameters for that call. That's even if the select can't be reached based on those parameters. That behaviour can get you some really erratic performance. Sometimes the query with one set of params runs fine and with a second runs slow, sometimes the second set of params are the fast ones and the first the slow.

    I normally recommend that a proc of that form gets split up, so that you call other procs based on the value of the params

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass