• psingla (5/6/2014)


    I have complex view and try to fetch data from it.

    In following code query 2 takes 1 sec to execute and query 1 keeps on running for hours.

    I tried to reduce the time of query 1 to same as query 2 but no luck.I tried force order,hash join,creating clustered on temp table,type conversion etc....

    Check the execution plan of query1 for timeout. You could post the actual execution plans for both queries if you are interested in more than guesses.

    “Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

    For fast, accurate and documented assistance in answering your questions, please read this article.
    Understanding and using APPLY, (I) and (II) Paul White
    Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden