SELECT     enr.sc, enr.pr,ENR.ID, ENR.ED, ENR.LD, enr.er, enr_1.sc,enr_1.pr, ENR_1.ED AS Expr1, ENR_1.LD AS Expr2, enr_1.er
FROM       ENR INNER JOIN ENR AS ENR_1 ON ENR.ID = ENR_1.ID AND ENR.YR = ENR_1.YR
WHERE      (ENR.DEL = 0) AND (ENR_1.DEL = 0) AND enr.ed > enr_1.ed AND (enr.ed <= enr_1.ld OR enr_1.ld IS NULL)  and enr.yr = '20' + SUBSTRING(db_name(),4,2)
ORDER BY   ENR.ED