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]
Jack Corbett
Consultant - Straight Path Solutions
Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a Question