• Do you use exactly the same code as used in the sproc?

    Or did you replace a few variables in the query with hardcoded values?

    It seems like the compiled version of the sproc is based on a different sample data distribution as the ad-hoc query leading to different execution plans...



    Lutz
    A pessimist is an optimist with experience.

    How to get fast answers to your question[/url]
    How to post performance related questions[/url]
    Links for Tally Table [/url] , Cross Tabs [/url] and Dynamic Cross Tabs [/url], Delimited Split Function[/url]