• praveen_vejandla (8/20/2013)


    I have a query that joins 3-4 tables out of which there are 2 temp tables. It is a simple join query and there are no parameters/variable passeds to the query.

    Query runs faster when run outside the stored procedure. If I put the same query as a stored procedure without any parameters, it is running slower.

    Query plan in both cases is same and amount of logical reads also same and set options also same.

    Any idea what could be the root cause behind this?

    Thanks.

    From this vague description it is impossible to tell. Can you post the query, the actual execution plan, the table ddl including indexes?

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/