-
Notifications
You must be signed in to change notification settings - Fork 23
/
RealECOrdersBy30days.sql
41 lines (36 loc) · 1.08 KB
/
RealECOrdersBy30days.sql
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
/*
select top 10 * from document_orders
REALEC FLOOD
REALEC APPRAISAL
REALEC ESCROW
REALEC TITLE
SELECT do_id,
ln_loan_id,
do_document_category,
do_date_initiated,
do_date_received,
do_last_update,
DATEDIFF(day, do_date_initiated, do_date_received) AS DaysBetween
from document_orders
where do_document_category LIKE '%REALEC%'
AND (do_date_initiated IS NULL
OR do_date_received IS NULL
OR do_last_update IS NULL)
--GROUP BY
ORDER BY DATEDIFF(day, do_date_initiated, do_date_received) desc
*/
SELECT 'ZeroToThirty'=
COUNT(CASE
WHEN DATEDIFF(day, do_date_initiated, do_date_received) BETWEEN 0 AND 29 THEN 'DaysBetween'
END),
COUNT(CASE
WHEN DATEDIFF(day, do_date_initiated, do_date_received) BETWEEN 30 AND 59 THEN 'DaysBetween'
END) AS ThirtyToSixty,
COUNT(CASE
WHEN DATEDIFF(day, do_date_initiated, do_date_received) BETWEEN 60 AND 89 THEN 'DaysBetween'
END) AS SixtyToNinety,
COUNT(CASE
WHEN DATEDIFF(day, do_date_initiated, do_date_received) >= 90 THEN 'DaysBetween'
END) AS NinetyPlus
from document_orders
where do_document_category LIKE '%REALEC%'