Repository navigation
Expand file tree
/
Copy pathaddComputedColumns.sql
More file actions
175 lines (164 loc) · 10.5 KB
/
Copy pathaddComputedColumns.sql
File metadata and controls
175 lines (164 loc) · 10.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
-- This script adds computed columns for delinquency percentages
alter table Portfolio_Summary
drop column pct_prepaid
alter table Portfolio_Summary
drop column pct_current
alter table Portfolio_Summary
drop column pct_30
alter table Portfolio_Summary
drop column pct_60
alter table Portfolio_Summary
drop column pct_90
alter table Portfolio_Summary
drop column pct_120
alter table Portfolio_Summary
drop column pct_REO
alter table Portfolio_Summary
drop column pct_Foreclosure
alter table Portfolio_Summary
drop column pct_Bankruptcy
alter table Portfolio_Summary
drop column pct_FHA_PreConveyance
alter table Portfolio_Summary
add pct_prepaid as CASE WHEN isnull([Active],1) = 0.00 THEN 0 ELSE (CONVERT(DECIMAL(10,2),100.0 * isnull([Prepaid or Current],0) / isnull([Active],1),1) ) END
alter table Portfolio_Summary
add pct_current as CASE WHEN isnull([Active],1) = 0.00 THEN 0 ELSE (CONVERT(DECIMAL(10,2),100.0 * isnull([Current Month],0) / isnull([Active],1),1) ) END
alter table Portfolio_Summary
add pct_30 as CASE WHEN isnull([Active],1) = 0.00 THEN 0 ELSE (CONVERT(DECIMAL(10,2),100.0 * isnull([30 Days Delinquent],0) / isnull([Active],1),1) ) END
alter table Portfolio_Summary
add pct_60 as CASE WHEN isnull([Active],1) = 0.00 THEN 0 ELSE (CONVERT(DECIMAL(10,2),100.0 * isnull([60 Days Delinquent],0) / isnull([Active],1),1) ) END
alter table Portfolio_Summary
add pct_90 as CASE WHEN isnull([Active],1) = 0.00 THEN 0 ELSE (CONVERT(DECIMAL(10,2),100.0 * isnull([90 Days Delinquent],0) / isnull([Active],1),1) ) END
alter table Portfolio_Summary
add pct_120 as CASE WHEN isnull([Active],1) = 0.00 THEN 0 ELSE (CONVERT(DECIMAL(10,2),100.0 * isnull([120+ Days Delinquent],0) / isnull([Active],1),1) ) END
alter table Portfolio_Summary
add pct_REO as CASE WHEN isnull([Active],1) = 0.00 THEN 0 ELSE (CONVERT(DECIMAL(10,2),100.0 * isnull([REO],0) / isnull([Active],1),1) ) END
alter table Portfolio_Summary
add pct_Foreclosure as CASE WHEN isnull([Active],1) = 0.00 THEN 0 ELSE (CONVERT(DECIMAL(10,2),100.0 * isnull([Foreclosure],0) / isnull([Active],1),1) ) END
alter table Portfolio_Summary
add pct_Bankruptcy as CASE WHEN isnull([Active],1) = 0.00 THEN 0 ELSE (CONVERT(DECIMAL(10,2),100.0 * isnull([Bankruptcy],0) / isnull([Active],1),1) ) END
alter table Portfolio_Summary
add pct_FHA_PreConveyance as CASE WHEN isnull([Active],1) = 0.00 THEN 0 ELSE (CONVERT(DECIMAL(10,2),100.0 * isnull([FHA_PreConveyance],0) / isnull([Active],1),1) ) END
alter table Portfolio_Summary
drop column UPB_pct_prepaid
alter table Portfolio_Summary
drop column UPB_pct_current
alter table Portfolio_Summary
drop column UPB_pct_30
alter table Portfolio_Summary
drop column UPB_pct_60
alter table Portfolio_Summary
drop column UPB_pct_90
alter table Portfolio_Summary
drop column UPB_pct_120
alter table Portfolio_Summary
drop column UPB_pct_REO
alter table Portfolio_Summary
drop column UPB_pct_Foreclosure
alter table Portfolio_Summary
drop column UPB_pct_Bankruptcy
alter table Portfolio_Summary
drop column UPB_pct_FHA_PreConveyance
alter table Portfolio_Summary
add UPB_pct_prepaid as CASE WHEN isnull([UPB_Active],1) = 0.00 THEN 0 ELSE (CONVERT(DECIMAL(10,2),100.0 * isnull([UPB_Prepaid or Current],0) / isnull([UPB_Active],1),1) ) END
alter table Portfolio_Summary
add UPB_pct_current as CASE WHEN isnull([UPB_Active],1) = 0.00 THEN 0 ELSE (CONVERT(DECIMAL(10,2),100.0 * isnull([UPB_Current Month],0) / isnull([UPB_Active],1),1) ) END
alter table Portfolio_Summary
add UPB_pct_30 as CASE WHEN isnull([UPB_Active],1) = 0.00 THEN 0 ELSE (CONVERT(DECIMAL(10,2),100.0 * isnull([UPB_30 Days Delinquent],0) / isnull([UPB_Active],1),1) ) END
alter table Portfolio_Summary
add UPB_pct_60 as CASE WHEN isnull([UPB_Active],1) = 0.00 THEN 0 ELSE (CONVERT(DECIMAL(10,2),100.0 * isnull([UPB_60 Days Delinquent],0) / isnull([UPB_Active],1),1) ) END
alter table Portfolio_Summary
add UPB_pct_90 as CASE WHEN isnull([UPB_Active],1) = 0.00 THEN 0 ELSE (CONVERT(DECIMAL(10,2),100.0 * isnull([UPB_90 Days Delinquent],0) / isnull([UPB_Active],1),1) ) END
alter table Portfolio_Summary
add UPB_pct_120 as CASE WHEN isnull([UPB_Active],1) = 0.00 THEN 0 ELSE (CONVERT(DECIMAL(10,2),100.0 * isnull([UPB_120+ Days Delinquent],0) / isnull([UPB_Active],1),1) ) END
alter table Portfolio_Summary
add UPB_pct_REO as CASE WHEN isnull([UPB_Active],1) = 0.00 THEN 0 ELSE (CONVERT(DECIMAL(10,2),100.0 * isnull([UPB_REO],0) / isnull([UPB_Active],1),1) ) END
alter table Portfolio_Summary
add UPB_pct_Foreclosure as CASE WHEN isnull([UPB_Active],1) = 0.00 THEN 0 ELSE (CONVERT(DECIMAL(10,2),100.0 * isnull([UPB_Foreclosure],0) / isnull([UPB_Active],1),1) ) END
alter table Portfolio_Summary
add UPB_pct_Bankruptcy as CASE WHEN isnull([UPB_Active],1) = 0.00 THEN 0 ELSE (CONVERT(DECIMAL(10,2),100.0 * isnull([UPB_Bankruptcy],0) / isnull([UPB_Active],1),1) ) END
alter table Portfolio_Summary
add UPB_pct_FHA_PreConveyance as CASE WHEN isnull([UPB_Active],1) = 0.00 THEN 0 ELSE (CONVERT(DECIMAL(10,2),100.0 * isnull([UPB_FHA_PreConveyance],0) / isnull([UPB_Active],1),1) ) END
select * from Portfolio_Summary
--- ********** INVESTOR ********** ---
alter table Portfolio_Summary_investor
drop column pct_prepaid
alter table Portfolio_Summary_investor
drop column pct_current
alter table Portfolio_Summary_investor
drop column pct_30
alter table Portfolio_Summary_investor
drop column pct_60
alter table Portfolio_Summary_investor
drop column pct_90
alter table Portfolio_Summary_investor
drop column pct_120
alter table Portfolio_Summary_investor
drop column pct_REO
alter table Portfolio_Summary_investor
drop column pct_Foreclosure
alter table Portfolio_Summary_investor
drop column pct_Bankruptcy
alter table Portfolio_Summary_investor
drop column pct_FHA_PreConveyance
alter table Portfolio_Summary_Investor
add pct_prepaid as CASE WHEN isnull([Active],1) = 0.00 THEN 0 ELSE (CONVERT(DECIMAL(10,2),100.0 * isnull([Prepaid or Current],0) / isnull([Active],1),1) ) END
alter table Portfolio_Summary_Investor
add pct_current as CASE WHEN isnull([Active],1) = 0.00 THEN 0 ELSE (CONVERT(DECIMAL(10,2),100.0 * isnull([Current Month],0) / isnull([Active],1),1) ) END
alter table Portfolio_Summary_Investor
add pct_30 as CASE WHEN isnull([Active],1) = 0.00 THEN 0 ELSE (CONVERT(DECIMAL(10,2),100.0 * isnull([30 Days Delinquent],0) / isnull([Active],1),1) ) END
alter table Portfolio_Summary_Investor
add pct_60 as CASE WHEN isnull([Active],1) = 0.00 THEN 0 ELSE (CONVERT(DECIMAL(10,2),100.0 * isnull([60 Days Delinquent],0) / isnull([Active],1),1) ) END
alter table Portfolio_Summary_Investor
add pct_90 as CASE WHEN isnull([Active],1) = 0.00 THEN 0 ELSE (CONVERT(DECIMAL(10,2),100.0 * isnull([90 Days Delinquent],0) / isnull([Active],1),1) ) END
alter table Portfolio_Summary_Investor
add pct_120 as CASE WHEN isnull([Active],1) = 0.00 THEN 0 ELSE (CONVERT(DECIMAL(10,2),100.0 * isnull([120+ Days Delinquent],0) / isnull([Active],1),1) ) END
alter table Portfolio_Summary_Investor
add pct_REO as CASE WHEN isnull([Active],1) = 0.00 THEN 0 ELSE (CONVERT(DECIMAL(10,2),100.0 * isnull([REO],0) / isnull([Active],1),1) ) END
alter table Portfolio_Summary_Investor
add pct_Foreclosure as CASE WHEN isnull([Active],1) = 0.00 THEN 0 ELSE (CONVERT(DECIMAL(10,2),100.0 * isnull([Foreclosure],0) / isnull([Active],1),1) ) END
alter table Portfolio_Summary_Investor
add pct_Bankruptcy as CASE WHEN isnull([Active],1) = 0.00 THEN 0 ELSE (CONVERT(DECIMAL(10,2),100.0 * isnull([Bankruptcy],0) / isnull([Active],1),1) ) END
alter table Portfolio_Summary_Investor
add pct_FHA_PreConveyance as CASE WHEN isnull([Active],1) = 0.00 THEN 0 ELSE (CONVERT(DECIMAL(10,2),100.0 * isnull([FHA_PreConveyance],0) / isnull([Active],1),1) ) END
alter table Portfolio_Summary_investor
drop column UPB_pct_prepaid
alter table Portfolio_Summary_investor
drop column UPB_pct_current
alter table Portfolio_Summary_investor
drop column UPB_pct_30
alter table Portfolio_Summary_investor
drop column UPB_pct_60
alter table Portfolio_Summary_investor
drop column UPB_pct_90
alter table Portfolio_Summary_investor
drop column UPB_pct_120
alter table Portfolio_Summary_investor
drop column UPB_pct_REO
alter table Portfolio_Summary_investor
drop column UPB_pct_Foreclosure
alter table Portfolio_Summary_investor
drop column UPB_pct_Bankruptcy
alter table Portfolio_Summary_investor
drop column UPB_pct_FHA_PreConveyance
alter table Portfolio_Summary_Investor
add UPB_pct_prepaid as CASE WHEN isnull([UPB_Active],1) = 0.00 THEN 0 ELSE (CONVERT(DECIMAL(10,2),100.0 * isnull([UPB_Prepaid or Current],0) / isnull([UPB_Active],1),1) ) END
alter table Portfolio_Summary_Investor
add UPB_pct_current as CASE WHEN isnull([UPB_Active],1) = 0.00 THEN 0 ELSE (CONVERT(DECIMAL(10,2),100.0 * isnull([UPB_Current Month],0) / isnull([UPB_Active],1),1) ) END
alter table Portfolio_Summary_Investor
add UPB_pct_30 as CASE WHEN isnull([UPB_Active],1) = 0.00 THEN 0 ELSE (CONVERT(DECIMAL(10,2),100.0 * isnull([UPB_30 Days Delinquent],0) / isnull([UPB_Active],1),1) ) END
alter table Portfolio_Summary_Investor
add UPB_pct_60 as CASE WHEN isnull([UPB_Active],1) = 0.00 THEN 0 ELSE (CONVERT(DECIMAL(10,2),100.0 * isnull([UPB_60 Days Delinquent],0) / isnull([UPB_Active],1),1) ) END
alter table Portfolio_Summary_Investor
add UPB_pct_90 as CASE WHEN isnull([UPB_Active],1) = 0.00 THEN 0 ELSE (CONVERT(DECIMAL(10,2),100.0 * isnull([UPB_90 Days Delinquent],0) / isnull([UPB_Active],1),1) ) END
alter table Portfolio_Summary_Investor
add UPB_pct_120 as CASE WHEN isnull([UPB_Active],1) = 0.00 THEN 0 ELSE (CONVERT(DECIMAL(10,2),100.0 * isnull([UPB_120+ Days Delinquent],0) / isnull([UPB_Active],1),1) ) END
alter table Portfolio_Summary_Investor
add UPB_pct_REO as CASE WHEN isnull([UPB_Active],1) = 0.00 THEN 0 ELSE (CONVERT(DECIMAL(10,2),100.0 * isnull([UPB_REO],0) / isnull([UPB_Active],1),1) ) END
alter table Portfolio_Summary_Investor
add UPB_pct_Foreclosure as CASE WHEN isnull([UPB_Active],1) = 0.00 THEN 0 ELSE (CONVERT(DECIMAL(10,2),100.0 * isnull([UPB_Foreclosure],0) / isnull([UPB_Active],1),1) ) END
alter table Portfolio_Summary_Investor
add UPB_pct_Bankruptcy as CASE WHEN isnull([UPB_Active],1) = 0.00 THEN 0 ELSE (CONVERT(DECIMAL(10,2),100.0 * isnull([UPB_Bankruptcy],0) / isnull([UPB_Active],1),1) ) END
alter table Portfolio_Summary_Investor
add UPB_pct_FHA_PreConveyance as CASE WHEN isnull([UPB_Active],1) = 0.00 THEN 0 ELSE (CONVERT(DECIMAL(10,2),100.0 * isnull([UPB_FHA_PreConveyance],0) / isnull([UPB_Active],1),1) ) END
select * from Portfolio_Summary_Investor