-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathData_Insert_Queries.sql
More file actions
88 lines (53 loc) · 2.06 KB
/
Copy pathData_Insert_Queries.sql
File metadata and controls
88 lines (53 loc) · 2.06 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
-- Using the required Database:
use [Data Engineering]
ALTER TABLE response
ALTER COLUMN response VARCHAR(50) COLLATE SQL_Latin1_General_CP1_CI_AS;
ALTER TABLE staging_table
ALTER COLUMN response VARCHAR(50) COLLATE SQL_Latin1_General_CP1_CI_AS;
ALTER TABLE measure
ALTER COLUMN measureIdChar VARCHAR(50) COLLATE SQL_Latin1_General_CP1_CI_AS;
ALTER TABLE staging_table
ALTER COLUMN measureId VARCHAR(50) COLLATE SQL_Latin1_General_CP1_CI_AS;
ALTER TABLE age_group
ALTER COLUMN age VARCHAR(50) COLLATE SQL_Latin1_General_CP1_CI_AS;
ALTER TABLE staging_table
ALTER COLUMN age VARCHAR(50) COLLATE SQL_Latin1_General_CP1_CI_AS;
-- Data Load for Topic Table from Staging Table:
insert into Topic select distinct TopicType,TopicId,TopicDesc
from Staging_Table;
-- Data Load for Measure Table:
insert into Measure (measureIdChar,MeasureDesc,TopicId,response_id)
select distinct MeasureId,MeasureDesc,TopicId,r.response_id
From Staging_Table s
left join response r on s.response = r.response;
-- Year Table Loading:
insert into Year
select distinct year
from Staging_Table;
-- Location Table Data Insert:
insert into Location
select distinct StateAbbr,States,Latitude,Longitude
from Staging_Table;
-- Data Insert for Response Table:
insert into Response(response)
select distinct response
from Staging_Table;
-- Age Group:
insert into Age_Group
select distinct age
from Staging_Table;
-- Data Table Insert:
insert into data
select distinct indexnum,StateAbbr,year,measuredesc,r.response_id,data_value,standard_error,Low_Confidence,High_Confidence,Sample_Size,Gender,a.ageId,StratificationID1,StratificationID2,StratificationID3,StratificationID4,SubMeasureID,DisplayOrder
from Staging_Table s
left join response r on s.Response = r.Response
left join Age_Group a on s.Age = a.Age
order by indexnum;
-- Checking Data for all the tables:
select * from Topic;
select * from Measure;
select * from year;
select * from Location;
select * from Age_Group;
select * from data;
select * from Response;