DECLARE @strLASTEOM AS VARCHAR(10)
DECLARE @LASTEOM AS DATETIME
SET @strLASTEOM = '2/28/2010'
SET @LASTEOM = CAST(@strLASTEOM AS DATETIME)
SELECT AS_OF_DT
, SUM(CASE STATUS WHEN 'CURRENT' THEN UPB ELSE 0 END) AS [CURRENT]
, SUM(CASE STATUS WHEN '30 DPD' THEN UPB ELSE 0 END) AS [30 DPD]
, SUM(CASE STATUS WHEN '60 DPD' THEN UPB ELSE 0 END) AS [60 DPD]
, SUM(CASE STATUS WHEN '90 DPD' THEN UPB ELSE 0 END) AS [90 DPD]
, SUM(CASE STATUS WHEN 'FC' THEN UPB ELSE 0 END) AS [FC]
, (SUM(UPB)- SUM(CASE STATUS WHEN 'REO' THEN UPB ELSE 0 END)- SUM(CASE STATUS WHEN 'CLOSED' THEN UPB ELSE 0 END))AS [PORTFOLIO_UPB]
, COUNT(DISTINCT VCC_LnNum) AS [Portfolio_Units]
, SUM(CASE STATUS WHEN 'REO' THEN UPB ELSE 0 END) AS [REO_UPB]
, COUNT(DISTINCT CASE WHEN STATUS = 'REO' THEN UPB ELSE 0 END) AS [REO_Units]
, SUM(CASE STATUS WHEN 'REO-SOLD' THEN UPB ELSE 0 END) AS [REO-SOLD_UPB]
, COUNT(DISTINCT CASE STATUS WHEN 'REO-SOLD' THEN AS_OF_DT ELSE 0 END) AS [REO-SOLD_Units]
, SUM(CASE BK_ACTIVE WHEN 'ACTIVE' THEN UPB ELSE 0 END) AS [BK_UPB]
, COUNT(DISTINCT CASE BK_ACTIVE WHEN 'ACTIVE' THEN UPB ELSE 0 END) AS [BK_Units]
FROM EOM_VCCPORT3_wMOD
WHERE((AS_OF_DT <= @LASTEOM AND AS_OF_DT >= DATEADD(d,-1,DATEADD(mm, DATEDIFF(m,0,@LASTEOM)-4,0))) OR
(AS_OF_DT = DATEADD(d,-1,DATEADD(mm, DATEDIFF(m,0,@LASTEOM)-11,0))))
AND (STATUS <> 'CLOSED')
AND (FICO BETWEEN 0 AND 10000)
AND (Prop_Type Like '%')
AND (Prop_St Like '%')
AND (Occ_Status Like '%')
AND ((MOD_NOW Like '%') Or (MOD_NOW IS NULL))
AND (VCC_LTV_Orig BETWEEN 1 AND 100)
GROUP BY AS_OF_DT
ORDER BY AS_OF_DT DESC
|