Select
L.LOAN_NUMBER,
FCS.STEP_CODE,
LS.FOR_STATUS,
UDF.USER_03_POSITION_FIELD_4B as HMP_FLAG,
FCS.ACTUAL_COMPLETION_DATE,
LETTER.LETTER_DATE,
BDEBI.LOAN_STATUS.MSP_LAST_RUN_DATE
FROM
BDE.LOAN_V L
INNER JOIN BDE.USER_DEFINED_V UDF ON (L.LOAN_NUMBER=UDF.LOAN_NUMBER)
INNER JOIN BDEBI.LOAN_STATUS LS ON (L.LOAN_NUMBER=LS.LOAN_NUMBER)
INNER JOIN BDE.FORECLOSURE_STEP_V FCS ON (L.LOAN_NUMBER = FCS.LOAN_NUMBER)
LEFT OUTER JOIN (SELECT LW.LOAN_NUMBER, LW.LETTER_DATE FROM BDE.ONLINE_LETTER_WRITER_V LW
WHERE LW.LETTER_ID IN ('LM500', 'LM507')) LETTER ON (L.LOAN_NUMBER = LETTER.LOAN_NUMBER)
WHERE
(
LS.FOR_STATUS IS NOT NULL
AND UDF.USER_03_POSITION_FIELD_4B = 'YY'
and FCS.STEP_CODE = '072' AND FCS.ACTUAL_COMPLETION_DATE IS NOT NULL
And FCS.ACTUAL_COMPLETION_DATE BETWEEN @variable('Select Start Date') AND @variable('Select End Date')
AND L.LOAN_NUMBER NOT IN (SELECT LOAN_NUMBER FROM BDE.FORECLOSURE_STEP_V
WHERE (STEP_CODE = '075' AND ACTUAL_COMPLETION_DATE IS NOT NULL)
)
)
GROUP BY
L.LOAN_NUMBER,
FCS.STEP_CODE,
LS.FOR_STATUS,
UDF.USER_03_POSITION_FIELD_4B,
FCS.ACTUAL_COMPLETION_DATE,
LETTER.LETTER_DATE
FOR FETCH ONLY WITH UR
|