Home Forums SQL Server 2008 T-SQL (SS2K8) OPTIMIZE FOR UNKNOWN (parameter sniffing problem) RE: OPTIMIZE FOR UNKNOWN (parameter sniffing problem)

  • Roland Alexander STL (9/21/2012)


    You can also use local variables for intermediaries. Assign your incoming parameters to local variables, then use the local variables in the predicates.

    Yep, that one solution on the blog's post...

    My main question is if it's necessary for ALL SPs...

    Say you have an SP to list customers with 4 filters: @city, @sex, @maritalstatus and @anualincome

    There's a select on the SP that takes all 4 parameters...

    Do I have to tell SQL Server to OPTIMIZE FOR UNKOWN?

    @city can have multiple values so can @anualincome, but @sex and @maritalstatus have few values.

    Thanks,

    Pedro



    If you need to work better, try working less...