1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
|
DECLARE @LASTEOM AS DATE
SET @LASTEOM = '6/30/2010'
DECLARE @strLSTEOM As Varchar
SET @strLSTEOM = CONVERT(VARCHAR, @LASTEOM)
SELECT STATUS,
SUM(CASE AS_OF_DT WHEN DATEADD(d,-1,DATEADD(mm, DATEDIFF(m,0,@LASTEOM)-4,0)) THEN UPB ELSE 0 END) AS EOM_6, -- want it to be @strLSTEOM,
SUM(CASE AS_OF_DT WHEN DATEADD(d,-1,DATEADD(mm, DATEDIFF(m,0,@LASTEOM)-3,0)) THEN UPB ELSE 0 END) AS EOM_5,
SUM(CASE AS_OF_DT WHEN DATEADD(d,-1,DATEADD(mm, DATEDIFF(m,0,@LASTEOM)-2,0)) THEN UPB ELSE 0 END) AS EOM_4,
SUM(CASE AS_OF_DT WHEN DATEADD(d,-1,DATEADD(mm, DATEDIFF(m,0,@LASTEOM)-1,0)) THEN UPB ELSE 0 END) AS EOM_3,
SUM(CASE AS_OF_DT WHEN DATEADD(d,-1,DATEADD(mm, DATEDIFF(m,0,@LASTEOM),0)) THEN UPB ELSE 0 END) AS EOM_2, -- want it to be @strLSTEOM,
SUM(CASE AS_OF_DT WHEN DATEADD(d,-1,DATEADD(mm, DATEDIFF(m,0,@LASTEOM)+1,0)) THEN UPB ELSE 0 END) AS @strLSTEOM, -- want it to be @strLSTEOM
SUM(CASE AS_OF_DT WHEN DATEADD(d,-1,DATEADD(mm, DATEDIFF(m,0,@LASTEOM)-11,0)) THEN UPB ELSE 0 END) AS Prior_Year -- want it to be @strLSTEOM,
FROM ScoreCard1
WHERE STATUS NOT IN('CLOSED', 'REO')
--GROUP BY STATUS
GROUP BY STATUS with CUBE
|