• Not really. The revised version (especially with more than 1 parameter) is likely to table scan all the time. That query has no single optimal plan

    The usual recommendations (and often things are a lot more complex than 1 if statement and 1 parameter) are:

    Call sub procedures from the if/else statement. Each proc will have it's own optimal plan

    Use RECOMPILE, on a procedure or statement level

    use dynamic SQL (not a good idea unless things are really, really complex)

    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