Home Forums SQL Server 2005 T-SQL (SS2K5) Correlated sub query takes more time to return result RE: Correlated sub query takes more time to return result

  • Your biggest problem is that you are using Functions against columns in the where of the subquery which will cause a table scan. You should first look at how you can eliminate that. Can you give us the definition of the table, some test data, and what you are trying to accomplish with the query? Can you convert it to a stored procedure where we can use table variables/temp tables?

    This may be what you want:

    [font="Courier New"]SELECT

        F.*

    FROM

        xxxxflow F JOIN

        (SELECT

            MAX(mstr_ordid) AS max_ord_id,

            Ord_Num,

             CONVERT(VARCHAR(10),b.date,101) AS date_string

        FROM

             xxxflow) B ON

            f.Ord_Num = B.Ord_Num AND

            CONVERT(VARCHAR(10),f.date_time,101) = B.date_string AND

            F.mstr_ordid = B.max_ord_id

    [/font]