• CELKO (12/15/2010)


    3) Why are you wasting time with dynamic SQL?

    Actually, dynamic SQL is the most efficient way to handle optional parameters in stored procedures.

    Using COALESCE, ISNULL, CASE and OR to express the same in static SQL leads to severe performance problems:

    1) They all lead to index scans instead of seeks

    2) Static SQL has issues with plan caching and parameter sniffing. See Erland Sommarskog's site for a more detailed explanation.

    -- Gianluca Sartori