SQLTeam.com | Weblogs | Forums

Query optimisation - 2


#1

Hi friends,

could any one help me to optimise the below query please

SELECT
TRA_REFNO
,MAX(Rep_Date) AS Rep_Date
FROM
(SELECT
Trans.TRA_REFNO
,Trans.TRA_DATE
,ISNULL(Credit_Summary.STR_BAL_PERIOD_DATE, Debit_Summary.STR_BAL_PERIOD_DATE) AS Rep_Date
FROM
NG.ST AS Credit_Summary
RIGHT OUTER JOIN NG.ST7 AS Trans ON Credit_Summary.STR_REFNO = Trans.TRA_STR_REFNO
INNER JOIN NG.DD ON Trans.TRA_REFNO = NG.DD.DDE_TRA_REFNO
LEFT OUTER JOIN NG.ST AS Debit_Summary ON Debit_Summary.STR_REFNO = NG.DD.DDE_STR_REFNO
WHERE
(Debit_Summary.STR_BAL_PERIOD_DATE IS NOT NULL)
OR
(Credit_Summary.STR_BAL_PERIOD_DATE IS NOT NULL)) AS T1
GROUP BY TRA_REFNO

thanks in advance
subha