• It appears that the CTE2 you have is excluding the first two loans, since the have disposition dates outside the ranges you've identified. In my example, I've made two assumptions, 1) the 'PS' record could appear outside the date window and 2) the listed Disposition codes represent the entire set.

    Here's my code sample "as is", I've made no attempts to standardize, tuning or otherwise "clean-up" anything.

    Hope this helps -

    IF NOT EXISTS(SELECT 1 FROM sys.objects where name = 'WMS_LoanDispositionData')

    BEGIN

    CREATE TABLE WMS_LoanDispositionData

    (

    Customer_Nbr_TxtVARCHAR(255),

    Loan_NbrBIGINT,

    Disposition_DtDATE,

    Disposition_Code_Txt VARCHAR(255)

    )

    INSERT INTO WMS_LoanDispositionData

    VALUES

    ('007849', '11613577', '2015-07-21', 'PS'),

    ('007849', '11613577', '2015-07-15', 'NP'),

    ('007849', '11613579', '2015-07-21', 'PS'),

    ('007849', '11613579', '2015-07-15', 'NP'),

    ('008120', '14364944', '2015-05-27', 'PM'),

    ('008120', '14364944', '2015-05-27', 'PS')

    END

    ;WITHcte1 AS (

    SELECT *,

    ROW_NUMBER() OVER (PARTITION BY a.loan_nbr

    ORDER BY a.Disposition_Dt DESC, a.Disposition_Code_Txt DESC) rn

    FROM WMS_LoanDispositionData a

    )

    SELECT *

    FROM cte1 C1a

    WHERE Disposition_Code_Txt = 'PS'

    AND EXISTS (SELECT 1 FROM cte1 C1b

    WHERE C1b.Customer_Nbr_Txt = c1a.Customer_Nbr_Txt

    ANDC1b.Loan_Nbr = C1a.Loan_Nbr

    AND C1b.Disposition_Code_Txt IN ('CI', 'CL', 'CR', 'NP', 'PA', 'PM')

    AND C1b.Disposition_Dt BETWEEN '2015-02-15' AND '2015-07-15'

    AND (C1b.rn - C1a.rn) = 1

    )