-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhow_resolved_splitting_inc.sql
More file actions
51 lines (45 loc) · 1.42 KB
/
how_resolved_splitting_inc.sql
File metadata and controls
51 lines (45 loc) · 1.42 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
USE insurance_complaints;
ALTER DATABASE insurance_complaints SET compatibility_LEVEL = 150;
DROP TABLE IF EXISTS complaint_resolution_table_inc;
CREATE TABLE complaint_resolution_table_inc
( complaint_no INT NOT NULL,
respondent_id INT NOT NULL,
resolution VARCHAR(255) NULL
);
INSERT INTO insurance_complaints.dbo.complaint_resolution_table_inc(
complaint_no, respondent_id, resolution
)
SELECT
ic.complaint_no,
ic.respondent_id,
TRIM(value) AS "resolution"
FROM dbo.complaints AS ic CROSS APPLY STRING_SPLIT(TRIM(how_resolved),';')
WHERE
ic.complaint_no IS NULL OR
ic.respondent_id IS NULL OR
ic.complaint_filed_against IS NULL OR
ic.complaint_filed_by IS NULL OR
ic.confirmed_complaint IS NULL OR
ic.received_date IS NULL OR
ic.closed_date IS NULL OR
ic.complaint_type IS NULL OR
ic.coverage_type IS NULL OR
ic.coverage_level IS NULL OR
ic.respondent_role IS NULL OR
ic.respondent_type IS NULL OR
ic.complainant_type IS NULL OR
ic.reason_complaint_filed IS NULL OR
ic.how_resolved IS NULL
GROUP BY ic.complaint_no, ic.respondent_id, TRIM(value);
-- PREVIEW OF COMPLAINT RESOLUTION TABLE.
SELECT TOP 100
*
FROM complaint_resolution_table_inc;
-- COUNT OF RECORDS
SELECT
COUNT(*)
FROM complaint_resolution_table_inc;
ALTER TABLE insurance_complaints.dbo.complaint_resolution_table_inc
ADD CONSTRAINT FK_complaint_resolution_hr
FOREIGN KEY(complaint_no, respondent_id)
REFERENCES complaints_inc(complaint_no,respondent_id)