-
Notifications
You must be signed in to change notification settings - Fork 0
/
dimensional_model_creation_scripts.qmd
12898 lines (12600 loc) · 717 KB
/
dimensional_model_creation_scripts.qmd
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
---
title: "DDL and Load Scripts"
format: html
editor: visual
---
```{css echo=FALSE}
#HIDE THIS CHUNK FROM KNITTED OUTPUT
h2 {margin: 2m 0 !important;}
details {
margin-left: 4em;
margin-bottom: .5rem;
}
summary {
margin-left: -2em;
}
```
```{r setup, include=FALSE}
#HIDE THIS CHUNK FROM KNITTED OUTPUT
knitr::opts_chunk$set(include=TRUE, echo=TRUE, eval = FALSE, warning = FALSE, fig.align = 'center') #results='hide') # needs to delete results='hide'
```
## 01 DDL (Creating and Permissioning Tables) Scripts
```{sql}
/*==============================================================*/
/* DBMS name: Amazon Redshift Database */
/* Created on: 9/7/2023 12:14:46 PM */
/*==============================================================*/
drop table FACT_Person_Program_Observation_Quarter;
drop table FACT_Person_Program_Outcome;
drop table FACT_Person_Program_Participation;
drop table FACT_Person_UI_Wage;
drop table FACT_Person_Quarterly_Program_Enrollment;
drop table DIM_CIP;
drop table DIM_County;
drop table DIM_Intake_Characteristics;
drop table DIM_Person;
drop table DIM_Program;
drop table DIM_State;
drop table DIM_Year_Quarter;
/*==============================================================*/
/* Table: DIM_CIP */
/*==============================================================*/
create table if not exists DIM_CIP (
CIP_Key BIGINT not null,
Classification_Code CHAR(7) not null,
Classification_Name VARCHAR(300) not null,
Category_Name VARCHAR(300) not null,
Series_Name VARCHAR(300) not null,
Series_Short_Name VARCHAR(300) not null,
Major_Group_Code CHAR(2) not null,
Major_Group_Name VARCHAR(300) not null,
constraint DIM_CIP_PK_IDX primary key (CIP_Key),
unique (Classification_Code)
);
/*==============================================================*/
/* Table: DIM_County */
/*==============================================================*/
create table if not exists DIM_County (
County_Key BIGINT not null,
County_FIPS_Code CHAR(5) not null,
County_Name VARCHAR(150) not null,
Rural_Urban_Continuum VARCHAR(300) not null,
Local_Workforce_Development_Area VARCHAR(30) not null,
constraint DIM_COUNTY_PK_IDX primary key (County_Key),
unique (County_FIPS_Code)
);
/*==============================================================*/
/* Table: DIM_Intake_Characteristics */
/*==============================================================*/
create table if not exists DIM_Intake_Characteristics (
Intake_Characteristics_Key BIGINT not null,
Highest_School_Grade_Completed_at_Program_Entry VARCHAR(2) not null,
Highest_Education_Level_Completed_at_Program_Entry VARCHAR(100) not null,
School_Status_at_Program_Entry VARCHAR(100) not null,
Employment_Status_at_Program_Entry VARCHAR(100) not null,
Long_Term_Unemployment_at_Program_Entry VARCHAR(3) not null,
Exhausting_TANF_Within_2_Yrs_at_Program_Entry VARCHAR(3) not null,
Foster_Care_Youth_Status_at_Program_Entry VARCHAR(3) not null,
Homeless_or_Runaway_at_Program_Entry VARCHAR(3) not null,
Ex_Offender_Status_at_Program_Entry VARCHAR(3) not null,
Low_Income_Status_at_Program_Entry VARCHAR(3) not null,
English_Language_Learner_at_Program_Entry VARCHAR(3) not null,
Low_Levels_of_Literacy_at_Program_Entry VARCHAR(3) not null,
Cultural_Barriers_at_Program_Entry VARCHAR(3) not null,
Single_Parent_at_Program_Entry VARCHAR(3) not null,
Displaced_Homemaker_at_Program_Entry VARCHAR(3) not null,
constraint DIM_INTAKE_CHARACTERISTICS_PK_IDX primary key (Intake_Characteristics_Key)
);
/*==============================================================*/
/* Table: DIM_Person */
/*==============================================================*/
create table if not exists DIM_Person (
Person_Key BIGINT not null,
Person_UID CHAR(64) not null,
Date_of_Birth DATE not null,
Gender VARCHAR(10) not null,
Ethnicity_American_Indian_or_Alaska_Native VARCHAR(3) not null,
Ethnicity_Asian VARCHAR(3) not null,
Ethnicity_Black_or_African_American VARCHAR(3) not null,
Ethnicity_Hispanic_or_Latino VARCHAR(3) not null,
Ethnicity_Native_Hawaiian_or_Other_Pacific_Islander VARCHAR(3) not null,
Ethnicity_White VARCHAR(3) not null,
Ethnicity_Other VARCHAR(3) not null,
constraint DIM_PERSON_PK_IDX primary key (Person_Key),
unique (Person_UID)
);
/*==============================================================*/
/* Table: DIM_Program */
/*==============================================================*/
create table if not exists DIM_Program (
Program_Key INTEGER not null,
Program_Name VARCHAR(75) not null,
constraint DIM_PROGRAM_PK_IDX primary key (Program_Key),
unique (Program_Name)
);
/*==============================================================*/
/* Table: DIM_State */
/*==============================================================*/
create table if not exists DIM_State (
State_Key INTEGER not null,
State_FIPS_Code CHAR(2) not null,
State_Abbreviation CHAR(2) not null,
State_Name VARCHAR(50) not null,
constraint DIM_STATE_PK_IDX primary key (State_Key),
unique (State_FIPS_Code),
unique (State_Abbreviation)
);
/*==============================================================*/
/* Table: DIM_Year_Quarter */
/*==============================================================*/
create table if not exists DIM_Year_Quarter (
Year_Quarter_Key INTEGER not null,
Calendar_Year CHAR(4) not null,
Calendar_Quarter CHAR(1) not null,
Quarter_Start_Date DATE not null,
Quarter_End_Date DATE not null,
constraint DIM_YEAR_QUARTER_PK_IDX primary key (Year_Quarter_Key),
unique (Calendar_Year, Calendar_Quarter)
);
/*==============================================================*/
/* Table: FACT_Person_Program_Observation_Quarter */
/*==============================================================*/
create table if not exists FACT_Person_Program_Observation_Quarter (
Person_Program_Observation_Quarter_ID BIGINT not null identity,
Person_Key BIGINT not null,
Program_Key INTEGER not null,
Observation_Year_Quarter_Key INTEGER not null,
County_of_Residence_Key BIGINT not null,
State_of_Residence_Key INTEGER not null,
CIP_Classification_Key BIGINT not null,
Enrolled_Entire_Quarter VARCHAR(3) not null,
Enrolled_First_Month_of_Quarter VARCHAR(3) not null,
Enrolled_Second_Month_of_Quarter VARCHAR(3) not null,
Enrolled_Third_Month_of_Quarter VARCHAR(3) not null,
Gross_Monthly_Income DECIMAL(14,2),
Net_Monthly_Income DECIMAL(14,2),
Date_of_Most_Recent_Career_Service DATE,
Received_Training VARCHAR(3) not null,
Eligible_Training_Provider_Name VARCHAR(75) not null,
Eligible_Training_Provider_Program_of_Study VARCHAR(100) not null,
Date_Entered_Training_1 DATE,
Type_of_Training_Service_1 VARCHAR(100) not null,
Date_Entered_Training_2 DATE,
Type_of_Training_Service_2 VARCHAR(100) not null,
Date_Entered_Training_3 DATE,
Type_of_Training_Service_3 VARCHAR(100) not null,
Participated_in_Postsecondary_Education_During_Program_Participation VARCHAR(3) not null,
Received_Training_from_Private_Section_Operated_Program VARCHAR(3) not null,
Enrolled_in_Secondary_Education_Program VARCHAR(3) not null,
Date_Enrolled_in_Post_Exit_Education_or_Training_Program DATE,
Youth_2nd_Quarter_Placement VARCHAR(50),
Youth_4th_Quarter_Placement VARCHAR(50),
Other_Reason_for_Exit VARCHAR(50) not null,
Migrant_and_Seasonal_Farmworker_Status VARCHAR(50) not null,
Individual_with_a_Disability VARCHAR(3) not null,
Zip_Code_of_Residence CHAR(5) not null,
Higher_Education_Student_Level VARCHAR(100) not null,
Higher_Education_Enrollment_Status VARCHAR(100) not null,
Higher_Education_Tuition_Status VARCHAR(100) not null,
constraint FACT_PERSON_PROGRAM_OBSERVATION_QUARTER_PK_IDX primary key (Person_Program_Observation_Quarter_ID),
unique (Person_Key, Program_Key, Observation_Year_Quarter_Key),
constraint FK_FACT_PERSON_PROGRAM_OBSERVATION_QUARTER__DIM_PERSON foreign key (Person_Key)
references DIM_Person (Person_Key),
constraint FK_FACT_PERSON_PROGRAM_OBSERVATION_QUARTER__DIM_PROGRAM foreign key (Program_Key)
references DIM_Program (Program_Key),
constraint FK_FACT_PERSON_PROGRAM_OBSERVATION_QUARTER__DIM_YEAR_QUARTER foreign key (Observation_Year_Quarter_Key)
references DIM_Year_Quarter (Year_Quarter_Key),
constraint FK_FACT_PERSON_PROGRAM_OBSERVATION_QUARTER__DIM_COUNTY foreign key (County_of_Residence_Key)
references DIM_County (County_Key),
constraint FK_FACT_PERSON_PROGRAM_OBSERVATION_QUARTER__DIM_STATE foreign key (State_of_Residence_Key)
references DIM_State (State_Key),
constraint FK_FACT_PERSON_PROGRAM_OBSERVATION_QUARTER__DIM_CIP foreign key (CIP_Classification_Key)
references DIM_CIP (CIP_Key)
);
/*==============================================================*/
/* Table: FACT_Person_Program_Outcome */
/*==============================================================*/
create table if not exists FACT_Person_Program_Outcome (
Person_Program_Outcomes_ID BIGINT not null identity,
Person_Key BIGINT not null,
Program_Key INTEGER not null,
Exit_Year_Quarter_Key INTEGER not null,
Employed_in_1st_Quarter_After_Exit_Quarter VARCHAR(30) not null,
Type_of_Employment_Match_1st_Quarter_After_Exit_Quarter VARCHAR(50) not null,
Earnings_1st_Quarter_After_Exit_Quarter DECIMAL(9,2),
Employed_in_2nd_Quarter_After_Exit_Quarter VARCHAR(30) not null,
Type_of_Employment_Match_2nd_Quarter_After_Exit_Quarter VARCHAR(50) not null,
Earnings_2nd_Quarter_After_Exit_Quarter DECIMAL(9,2),
Employed_in_3rd_Quarter_After_Exit_Quarter VARCHAR(30) not null,
Type_of_Employment_Match_3rd_Quarter_After_Exit_Quarter VARCHAR(50) not null,
Earnings_3rd_Quarter_After_Exit_Quarter DECIMAL(9,2),
Employed_in_4th_Quarter_After_Exit_Quarter VARCHAR(30) not null,
Type_of_Employment_Match_4th_Quarter_After_Exit_Quarter VARCHAR(50) not null,
Earnings_4th_Quarter_After_Exit_Quarter DECIMAL(9,2),
Employment_Related_to_Training VARCHAR(3),
Retention_with_Same_Employer_2nd_Quarter_and_4th_Quarter VARCHAR(3) not null,
Type_of_Recognized_Credential_1 VARCHAR(100) not null,
Type_of_Recognized_Credential_2 VARCHAR(100) not null,
Type_of_Recognized_Credential_3 VARCHAR(100) not null,
Date_Attained_Recognized_Credential_1 DATE,
Date_Attained_Recognized_Credential_2 DATE,
Date_Attained_Recognized_Credential_3 DATE,
Date_of_Most_Recent_Measurable_Skill_Gain_Educational_Functional_Level DATE,
Date_of_Most_Recent_Measurable_Skill_Gain_Postsecondary_Transcript DATE,
Date_of_Most_Recent_Measurable_Skill_Gain_Secondary_Transcript DATE,
Date_of_Most_Recent_Measurable_Skill_Gain_Training_Milestone DATE,
Date_of_Most_Recent_Measurable_Skill_Gain_Skills_Progression DATE,
Date_Enrolled_in_Education_or_Training_Program_Leading_to_Credential_or_Employment DATE,
Date_Completed_an_Education_or_Training_Program_Leading_to_Credential_or_Employment DATE,
Date_Attained_Graduate_or_Post_Graduate_Degree DATE,
constraint FACT_PERSON_PROGRAM_OUTCOME_PK_IDX primary key (Person_Program_Outcomes_ID),
unique (Person_Key, Program_Key, Exit_Year_Quarter_Key),
constraint FK_FACT_PERSON_PROGRAM_OUTCOME__DIM_PERSON foreign key (Person_Key)
references DIM_Person (Person_Key),
constraint FK_FACT_PERSON_PROGRAM_OUTCOME__DIM_PROGRAM foreign key (Program_Key)
references DIM_Program (Program_Key),
constraint FK_FACT_PERSON_PROGRAM_OUTCOME__DIM_YEAR_QUARTER foreign key (Exit_Year_Quarter_Key)
references DIM_Year_Quarter (Year_Quarter_Key)
);
/*==============================================================*/
/* Table: FACT_Person_Program_Participation */
/*==============================================================*/
create table if not exists FACT_Person_Program_Participation (
Person_Program_Participation_ID BIGINT not null identity,
Person_Key BIGINT not null,
Intake_Characteristics_Key BIGINT not null,
Program_Key INTEGER not null,
Entry_Year_Quarter_Key INTEGER not null,
Exit_Year_Quarter_Key INTEGER not null,
County_of_Residence_Key BIGINT not null,
State_of_Residence_Key INTEGER not null,
CIP_Classification_Key BIGINT not null,
Gross_Monthly_Income DECIMAL(14,2),
Net_Monthly_Income DECIMAL(14,2),
Date_of_Most_Recent_Career_Service DATE,
Received_Training VARCHAR(3) not null,
Eligible_Training_Provider_Name VARCHAR(75) not null,
Eligible_Training_Provider_Program_of_Study VARCHAR(100) not null,
Date_Entered_Training_1 DATE,
Type_of_Training_Service_1 VARCHAR(100) not null,
Date_Entered_Training_2 DATE,
Type_of_Training_Service_2 VARCHAR(100) not null,
Date_Entered_Training_3 DATE,
Type_of_Training_Service_3 VARCHAR(100) not null,
Participated_in_Postsecondary_Education_During_Program_Participation VARCHAR(3) not null,
Received_Training_from_Private_Section_Operated_Program VARCHAR(3) not null,
Enrolled_in_Secondary_Education_Program VARCHAR(3) not null,
Date_Enrolled_in_Post_Exit_Education_or_Training_Program DATE,
Youth_2nd_Quarter_Placement VARCHAR(50),
Youth_4th_Quarter_Placement VARCHAR(50),
Incarcerated_at_Program_Entry VARCHAR(3) not null,
Date_Released_from_Incarceration DATE,
Other_Reason_for_Exit VARCHAR(50) not null,
Migrant_and_Seasonal_Farmworker_Status VARCHAR(50) not null,
Individual_with_a_Disability VARCHAR(3) not null,
Zip_Code_of_Residence CHAR(5) not null,
Higher_Education_Student_Level VARCHAR(100) not null,
Higher_Education_Enrollment_Status VARCHAR(100) not null,
Higher_Education_Tuition_Status VARCHAR(100) not null,
constraint FACT_PERSON_PROGRAM_PARTICIPATION_PK_IDX primary key (Person_Program_Participation_ID),
unique (Person_Key, Program_Key, Entry_Year_Quarter_Key, Exit_Year_Quarter_Key),
constraint FK_FACT_PERSON_PROGRAM_PARTICIPATION__DIM_PROGRAM foreign key (Program_Key)
references DIM_Program (Program_Key),
constraint FK_FACT_PERSON_PROGRAM_PARTICIPATION__DIM_YEAR_QUARTER__ENTRY_YEAR foreign key (Entry_Year_Quarter_Key)
references DIM_Year_Quarter (Year_Quarter_Key),
constraint FK_FACT_PERSON_PROGRAM_PARTICIPATION__DIM_PERSON foreign key (Person_Key)
references DIM_Person (Person_Key),
constraint FK_FACT_PERSON_PROGRAM_PARTICIPATION__DIM_YEAR_QUARTER__EXIT_YEAR foreign key (Exit_Year_Quarter_Key)
references DIM_Year_Quarter (Year_Quarter_Key),
constraint FK_FACT_PERSON_PROGRAM_PARTICIPATION__DIM_INTAKE_CHARACTERISTICS foreign key (Intake_Characteristics_Key)
references DIM_Intake_Characteristics (Intake_Characteristics_Key),
constraint FK_FACT_PERSON_PROGRAM_PARTICIPATION__DIM_COUNTY foreign key (County_of_Residence_Key)
references DIM_County (County_Key),
constraint FK_FACT_PERSON_PROGRAM__FACT_PERSON_PROGRAM_PARTICIPATION__DIM_CIP_DIM_CIP foreign key (CIP_Classification_Key)
references DIM_CIP (CIP_Key),
constraint FK_FACT_PERSON_PROGRAM__FACT_PERSON_PROGRAM_PARTICIPATION__DIM_STATE_DIM_STATE foreign key (State_of_Residence_Key)
references DIM_State (State_Key)
);
/*==============================================================*/
/* Table: FACT_Person_UI_Wage */
/*==============================================================*/
create table if not exists FACT_Person_UI_Wage (
Person_UI_Wage_ID BIGINT not null identity,
Person_Key BIGINT not null,
Year_Quarter_Key INTEGER not null,
UI_Quarterly_Wages DECIMAL(10,0) not null,
constraint FACT_PERSON_UI_WAGE_PK_IDX primary key (Person_UI_Wage_ID),
unique (Person_Key, Year_Quarter_Key),
constraint FK_FACT_PERSON_UI_WAGE__DIM_PERSON foreign key (Person_Key)
references DIM_Person (Person_Key),
constraint FK_FACT_PERSON_UI_WAGE__DIM_YEAR_QUARTER foreign key (Year_Quarter_Key)
references DIM_Year_Quarter (Year_Quarter_Key)
);
/*==============================================================*/
/* Table: FACT_Person_Quarterly_Program_Enrollment */
/*==============================================================*/
create table if not exists FACT_Person_Quarterly_Program_Enrollment (
Person_Quarterly_Program_Enrollment_ID BIGINT not null identity,
Person_Key BIGINT not null,
Program_Key INTEGER not null,
Enrollment_Quarter_Key INTEGER not null,
Enrolled_Entire_Quarter VARCHAR(3) not null,
Enrolled_First_Month_of_Quarter VARCHAR(3) not null,
Enrolled_Second_Month_of_Quarter VARCHAR(3) not null,
Enrolled_Third_Month_of_Quarter VARCHAR(3) not null,
constraint PK_FACT_Person_Quarterly_Program_Enrollment primary key (Person_Quarterly_Program_Enrollment_ID),
unique (Person_Key, Program_Key, Enrollment_Quarter_Key),
constraint FK_FACT_PERSON_QUARTERLY_PROGRAM_ENROLLMENT_DIM_PROGRAM foreign key (Program_Key)
references DIM_Program (Program_Key),
constraint FK_FACT_PERSON_QUARTERLY_PROGRAM_ENROLLMENT_DIM_YEAR_QUARTER foreign key (Enrollment_Quarter_Key)
references DIM_Year_Quarter (Year_Quarter_Key),
constraint FK_FACT_PERSON_QUARTERLY_PROGRAM_ENROLLMENT_DIM_PERSON foreign key (Person_Key)
references DIM_Person (Person_Key)
);
GRANT SELECT ON TABLE DIM_Person TO group ci_read_group;
GRANT UPDATE, SELECT, DELETE, INSERT ON TABLE DIM_Person TO group db_t00113_rw;
GRANT SELECT ON TABLE DIM_Program TO group ci_read_group;
GRANT UPDATE, SELECT, DELETE, INSERT ON TABLE DIM_Program TO group db_t00113_rw;
GRANT SELECT ON TABLE DIM_Intake_Characteristics TO group ci_read_group;
GRANT UPDATE, SELECT, DELETE, INSERT ON TABLE DIM_Intake_Characteristics TO group db_t00113_rw;
GRANT SELECT ON TABLE DIM_Year_Quarter TO group ci_read_group;
GRANT UPDATE, SELECT, DELETE, INSERT ON TABLE DIM_Year_Quarter TO group db_t00113_rw;
GRANT SELECT ON TABLE DIM_County TO group ci_read_group;
GRANT UPDATE, SELECT, DELETE, INSERT ON TABLE DIM_County TO group db_t00113_rw;
GRANT SELECT ON TABLE FACT_Person_Program_Observation_Quarter TO group ci_read_group;
GRANT UPDATE, SELECT, DELETE, INSERT ON TABLE FACT_Person_Program_Observation_Quarter TO group db_t00113_rw;
GRANT SELECT ON TABLE FACT_Person_Program_Outcome TO group ci_read_group;
GRANT UPDATE, SELECT, DELETE, INSERT ON TABLE FACT_Person_Program_Outcome TO group db_t00113_rw;
GRANT SELECT ON TABLE FACT_Person_Program_Participation TO group ci_read_group;
GRANT UPDATE, SELECT, DELETE, INSERT ON TABLE FACT_Person_Program_Participation TO group db_t00113_rw;
GRANT SELECT ON TABLE FACT_Person_UI_Wage TO group ci_read_group;
GRANT UPDATE, SELECT, DELETE, INSERT ON TABLE FACT_Person_UI_Wage TO group db_t00113_rw;
GRANT SELECT ON TABLE FACT_Person_Quarterly_Program_Enrollment TO group ci_read_group;
GRANT UPDATE, SELECT, DELETE, INSERT ON TABLE FACT_Person_Quarterly_Program_Enrollment TO group db_t00113_rw;
```
## 02 Load Scripts
### FACT Person Outcome Tables
#### JOINT PIRL
```{sql}
/*
This script will load the the FACT_Person_Program_Outcome table with data for the "Adult Education (JOINT)" program.
Step 1
The data is collected from the source table (ds_ar_dws.jointpirl_raw_data) and returned in the ctePIRL comment table expression (CTE).
Any reference values or boolean values are converted to text strings.
Step 2
The ctePirl data is then process thru the cteFactData CTE which looks up the dimension keys.
Step 3
The cteFactData is inserted into the fact table. Any keys that could not be found via the lookup are set to 0.
*/
-- FACT Person Program Outcome (Joint PIRL)
INSERT INTO FACT_Person_Program_Outcome (Person_Key, Program_Key, Exit_Year_Quarter_Key, Employed_in_1st_Quarter_After_Exit_Quarter,
Type_of_Employment_Match_1st_Quarter_After_Exit_Quarter, Earnings_1st_Quarter_After_Exit_Quarter,
Employed_in_2nd_Quarter_After_Exit_Quarter, Type_of_Employment_Match_2nd_Quarter_After_Exit_Quarter,
Earnings_2nd_Quarter_After_Exit_Quarter, Employed_in_3rd_Quarter_After_Exit_Quarter,
Type_of_Employment_Match_3rd_Quarter_After_Exit_Quarter, Earnings_3rd_Quarter_After_Exit_Quarter,
Employed_in_4th_Quarter_After_Exit_Quarter, Type_of_Employment_Match_4th_Quarter_After_Exit_Quarter,
Earnings_4th_Quarter_After_Exit_Quarter, Employment_Related_to_Training,
Retention_with_Same_Employer_2nd_Quarter_and_4th_Quarter, Type_of_Recognized_Credential_1,
Type_of_Recognized_Credential_2, Type_of_Recognized_Credential_3, Date_Attained_Recognized_Credential_1,
Date_Attained_Recognized_Credential_2, Date_Attained_Recognized_Credential_3,
Date_of_Most_Recent_Measurable_Skill_Gain_Educational_Functional_Level,
Date_of_Most_Recent_Measurable_Skill_Gain_Postsecondary_Transcript,
Date_of_Most_Recent_Measurable_Skill_Gain_Secondary_Transcript,
Date_of_Most_Recent_Measurable_Skill_Gain_Training_Milestone,
Date_of_Most_Recent_Measurable_Skill_Gain_Skills_Progression,
Date_Enrolled_in_Education_or_Training_Program_Leading_to_Credential_or_Employment,
Date_Completed_an_Education_or_Training_Program_Leading_to_Credential_or_Employment,
Date_Attained_Graduate_or_Post_Graduate_Degree)
WITH ctePirl (social_security_number, program_name, exit_date, Employed_in_1st_Quarter_After_Exit_Quarter,
Type_of_Employment_Match_1st_Quarter_After_Exit_Quarter, Earnings_1st_Quarter_After_Exit_Quarter,
Employed_in_2nd_Quarter_After_Exit_Quarter, Type_of_Employment_Match_2nd_Quarter_After_Exit_Quarter,
Earnings_2nd_Quarter_After_Exit_Quarter, Employed_in_3rd_Quarter_After_Exit_Quarter,
Type_of_Employment_Match_3rd_Quarter_After_Exit_Quarter, Earnings_3rd_Quarter_After_Exit_Quarter,
Employed_in_4th_Quarter_After_Exit_Quarter, Type_of_Employment_Match_4th_Quarter_After_Exit_Quarter,
Earnings_4th_Quarter_After_Exit_Quarter, Employment_Related_to_Training,
Retention_with_Same_Employer_2nd_Quarter_and_4th_Quarter, Type_of_Recognized_Credential_1,
Type_of_Recognized_Credential_2, Type_of_Recognized_Credential_3, Date_Attained_Recognized_Credential_1,
Date_Attained_Recognized_Credential_2, Date_Attained_Recognized_Credential_3,
Date_of_Most_Recent_Measurable_Skill_Gain_Educational_Functional_Level,
Date_of_Most_Recent_Measurable_Skill_Gain_Postsecondary_Transcript,
Date_of_Most_Recent_Measurable_Skill_Gain_Secondary_Transcript,
Date_of_Most_Recent_Measurable_Skill_Gain_Training_Milestone,
Date_of_Most_Recent_Measurable_Skill_Gain_Skills_Progression,
Date_Enrolled_in_Education_or_Training_Program_Leading_to_Credential_or_Employment,
Date_Completed_an_Education_or_Training_Program_Leading_to_Credential_or_Employment,
Date_Attained_Graduate_or_Post_Graduate_Degree)
AS
(
SELECT social_security_number,
CAST('Adult Education (JOINT)' AS VARCHAR(75)) AS program_name,
date_of_program_exit_wioa,
CASE
WHEN employed_in_1st_quarter_after_exit_quarter_wioa IN (1, 2, 3) THEN 'Yes'
ELSE 'No'
END,
CASE type_of_employment_match_1st_quarter_after_exit_quarter_wioa
WHEN 1 THEN 'UI Wage Data'
WHEN 2 THEN 'Federal Employment Records (OPM, USPS)'
WHEN 3 THEN 'Military Employment Records (DOD)'
WHEN 4 THEN 'Non UI verification'
WHEN 5 THEN 'Information not yet available'
WHEN 0 THEN 'Not employed'
ELSE ''
END,
COALESCE(earnings_1st_quarter_after_exit_quarter_wioa, 0),
CASE
WHEN employed_in_2nd_quarter_after_exit_quarter_wioa IN (1, 2, 3) THEN 'Yes'
ELSE 'No'
END,
CASE type_of_employment_match_2nd_quarter_after_exit_quarter_wioa
WHEN 1 THEN 'UI Wage Data'
WHEN 2 THEN 'Federal Employment Records (OPM, USPS)'
WHEN 3 THEN 'Military Employment Records (DOD)'
WHEN 4 THEN 'Non UI verification'
WHEN 5 THEN 'Information not yet available'
WHEN 0 THEN 'Not employed'
ELSE ''
END,
COALESCE(earnings_2nd_quarter_after_exit_quarter_wioa, 0),
CASE
WHEN employed_in_3rd_quarter_after_exit_quarter_wioa IN (1, 2, 3) THEN 'Yes'
ELSE 'No'
END,
CASE type_of_employment_match_3rd_quarter_after_exit_quarter_wioa
WHEN 1 THEN 'UI Wage Data'
WHEN 2 THEN 'Federal Employment Records (OPM, USPS)'
WHEN 3 THEN 'Military Employment Records (DOD)'
WHEN 4 THEN 'Non UI verification'
WHEN 5 THEN 'Information not yet available'
WHEN 0 THEN 'Not employed'
ELSE ''
END,
COALESCE(earnings_3rd_quarter_after_exit_quarter_wioa, 0),
CASE
WHEN employed_in_4th_quarter_after_exit_quarter_wioa IN (1, 2, 3) THEN 'Yes'
ELSE 'No'
END,
CASE type_of_employment_match_4th_quarter_after_exit_quarter_wioa
WHEN 1 THEN 'UI Wage Data'
WHEN 2 THEN 'Federal Employment Records (OPM, USPS)'
WHEN 3 THEN 'Military Employment Records (DOD)'
WHEN 4 THEN 'Non UI verification'
WHEN 5 THEN 'Information not yet available'
WHEN 0 THEN 'Not employed'
ELSE ''
END,
COALESCE(earnings_4th_quarter_after_exit_quarter_wioa, 0),
CASE employment_related_to_training_2nd_quarter_after_exit_wioa
WHEN 1 THEN 'Yes'
WHEN 0 THEN 'No'
ELSE ''
END,
CASE retention_with_the_same_employer_in_the_2nd_quarter_and_the_4th_quarter_wioa
WHEN 1 THEN 'Yes'
WHEN 0 THEN 'No'
ELSE ''
END,
CASE type_of_recognized_credential_wioa
WHEN 1 THEN 'Secondary School Diploma/or equivalency'
WHEN 2 THEN 'AA or AS Diploma/Degree'
WHEN 3 THEN 'BA or BS Diploma/Degree'
WHEN 4 THEN 'Occupational Licensure'
WHEN 5 THEN 'Occupational Certificate'
WHEN 6 THEN 'Occupational Certification'
WHEN 7 THEN 'Other Recognized Diploma, Degree, or Certificate'
WHEN 0 THEN 'No recognized credential'
ELSE ''
END,
CASE type_of_recognized_credential_2_wioa
WHEN 1 THEN 'Secondary School Diploma/or equivalency'
WHEN 2 THEN 'AA or AS Diploma/Degree'
WHEN 3 THEN 'BA or BS Diploma/Degree'
WHEN 4 THEN 'Occupational Licensure'
WHEN 5 THEN 'Occupational Certificate'
WHEN 6 THEN 'Occupational Certification'
WHEN 7 THEN 'Other Recognized Diploma, Degree, or Certificate'
WHEN 0 THEN 'No recognized credential'
ELSE ''
END,
CASE type_of_recognized_credential_3_wioa
WHEN 1 THEN 'Secondary School Diploma/or equivalency'
WHEN 2 THEN 'AA or AS Diploma/Degree'
WHEN 3 THEN 'BA or BS Diploma/Degree'
WHEN 4 THEN 'Occupational Licensure'
WHEN 5 THEN 'Occupational Certificate'
WHEN 6 THEN 'Occupational Certification'
WHEN 7 THEN 'Other Recognized Diploma, Degree, or Certificate'
WHEN 0 THEN 'No recognized credential'
ELSE ''
END,
COALESCE(date_attained_recognized_credential_wioa, CAST('9999-01-01' AS DATE)),
COALESCE(date_attained_recognized_credential_2_wioa, CAST('9999-01-01' AS DATE)),
COALESCE(date_attained_recognized_credential_3_wioa, CAST('9999-01-01' AS DATE)),
COALESCE(date_of_most_recent_measurable_skill_gains_educational_functioning_level_efl_wioa, CAST('9999-01-01' AS DATE)),
COALESCE(date_of_most_recent_measurable_skill_gains_postsecondary_transcript_report_card_wioa, CAST('9999-01-01' AS DATE)),
COALESCE(date_of_most_recent_measurable_skill_gains_secondary_transcript_report_card_wioa, CAST('9999-01-01' AS DATE)),
COALESCE(date_of_most_recent_measurable_skill_gains_training_milestone_wioa, CAST('9999-01-01' AS DATE)),
COALESCE(date_of_most_recent_measurable_skill_gains_skills_progression_wioa, CAST('9999-01-01' AS DATE)),
COALESCE(date_enrolled_in_post_exit_education_or_training_program_leading_to_a_recognized_postsecondary_credential_wioa, CAST('9999-01-01' AS DATE)),
COALESCE(date_completed_during_program_participation_an_education_or_training_program_leading_to_a_recognized_credential_or_employment, CAST('9999-01-01' AS DATE)),
COALESCE(date_attained_graduate_post_graduate_degree_wioa, CAST('9999-01-01' AS DATE))
FROM ds_ar_dws.jointpirl_raw_data
WHERE DATEPART(year, date_of_program_exit_wioa) >= 2010
AND ssn_valid_format = 1
AND adult_education_wioa = 1
),
cteFactData
AS
(
SELECT --Lookup Person Surrogate Key
(
SELECT DIM_Person.Person_Key
FROM DIM_Person
WHERE DIM_Person.Person_UID = pirl.social_security_number
) AS Person_Key,
--Lookup Program Surrogate Key
(
SELECT DIM_Program.Program_Key
FROM DIM_Program
WHERE DIM_Program.Program_Name = pirl.program_name
) AS Program_Key,
--Lookup Exit Year Quarter Surrogate Key
(
SELECT exit_qtr.Year_Quarter_Key
FROM DIM_Year_Quarter exit_qtr
WHERE pirl.exit_date between exit_qtr.quarter_start_date and exit_qtr.quarter_end_date
) AS Exit_Year_Quarter_Key,
pirl.Employed_in_1st_Quarter_After_Exit_Quarter,
pirl.Type_of_Employment_Match_1st_Quarter_After_Exit_Quarter,
pirl.Earnings_1st_Quarter_After_Exit_Quarter,
pirl.Employed_in_2nd_Quarter_After_Exit_Quarter,
pirl.Type_of_Employment_Match_2nd_Quarter_After_Exit_Quarter,
pirl.Earnings_2nd_Quarter_After_Exit_Quarter,
pirl.Employed_in_3rd_Quarter_After_Exit_Quarter,
pirl.Type_of_Employment_Match_3rd_Quarter_After_Exit_Quarter,
pirl.Earnings_3rd_Quarter_After_Exit_Quarter,
pirl.Employed_in_4th_Quarter_After_Exit_Quarter,
pirl.Type_of_Employment_Match_4th_Quarter_After_Exit_Quarter,
pirl.Earnings_4th_Quarter_After_Exit_Quarter,
pirl.Employment_Related_to_Training,
pirl.Retention_with_Same_Employer_2nd_Quarter_and_4th_Quarter,
pirl.Type_of_Recognized_Credential_1,
pirl.Type_of_Recognized_Credential_2,
pirl.Type_of_Recognized_Credential_3,
pirl.Date_Attained_Recognized_Credential_1,
pirl.Date_Attained_Recognized_Credential_2,
pirl.Date_Attained_Recognized_Credential_3,
pirl.Date_of_Most_Recent_Measurable_Skill_Gain_Educational_Functional_Level,
pirl.Date_of_Most_Recent_Measurable_Skill_Gain_Postsecondary_Transcript,
pirl.Date_of_Most_Recent_Measurable_Skill_Gain_Secondary_Transcript,
pirl.Date_of_Most_Recent_Measurable_Skill_Gain_Training_Milestone,
pirl.Date_of_Most_Recent_Measurable_Skill_Gain_Skills_Progression,
pirl.Date_Enrolled_in_Education_or_Training_Program_Leading_to_Credential_or_Employment,
pirl.Date_Completed_an_Education_or_Training_Program_Leading_to_Credential_or_Employment,
pirl.Date_Attained_Graduate_or_Post_Graduate_Degree
FROM ctePirl pirl
)
SELECT COALESCE(Person_Key, 0),
COALESCE(Program_Key, 0),
COALESCE(Exit_Year_Quarter_Key, 0),
Employed_in_1st_Quarter_After_Exit_Quarter,
Type_of_Employment_Match_1st_Quarter_After_Exit_Quarter, Earnings_1st_Quarter_After_Exit_Quarter,
Employed_in_2nd_Quarter_After_Exit_Quarter, Type_of_Employment_Match_2nd_Quarter_After_Exit_Quarter,
Earnings_2nd_Quarter_After_Exit_Quarter, Employed_in_3rd_Quarter_After_Exit_Quarter,
Type_of_Employment_Match_3rd_Quarter_After_Exit_Quarter, Earnings_3rd_Quarter_After_Exit_Quarter,
Employed_in_4th_Quarter_After_Exit_Quarter, Type_of_Employment_Match_4th_Quarter_After_Exit_Quarter,
Earnings_4th_Quarter_After_Exit_Quarter, Employment_Related_to_Training,
Retention_with_Same_Employer_2nd_Quarter_and_4th_Quarter, Type_of_Recognized_Credential_1,
Type_of_Recognized_Credential_2, Type_of_Recognized_Credential_3, Date_Attained_Recognized_Credential_1,
Date_Attained_Recognized_Credential_2, Date_Attained_Recognized_Credential_3,
Date_of_Most_Recent_Measurable_Skill_Gain_Educational_Functional_Level,
Date_of_Most_Recent_Measurable_Skill_Gain_Postsecondary_Transcript,
Date_of_Most_Recent_Measurable_Skill_Gain_Secondary_Transcript,
Date_of_Most_Recent_Measurable_Skill_Gain_Training_Milestone,
Date_of_Most_Recent_Measurable_Skill_Gain_Skills_Progression,
Date_Enrolled_in_Education_or_Training_Program_Leading_to_Credential_or_Employment,
Date_Completed_an_Education_or_Training_Program_Leading_to_Credential_or_Employment,
Date_Attained_Graduate_or_Post_Graduate_Degree
FROM cteFactData;
```
#### Adult Education
```{sql}
/*
This script will load the the FACT_Person_Program_Outcome table with data for the "Adult Education (WIOA)" program.
Step 1
The data is collected from the source table (ds_ar_dws.pirl) and returned in the ctePIRL comment table expression (CTE).
Any reference values or boolean values are converted to text strings.
Step 2
The ctePirl data is then process thru the cteFactData CTE which looks up the dimension keys.
Step 3
The cteFactData is inserted into the fact table. Any keys that could not be found via the lookup are set to 0.
*/
-- FACT Person Program Outcome (PIRL - Adult Education)
INSERT INTO FACT_Person_Program_Outcome (Person_Key, Program_Key, Exit_Year_Quarter_Key, Employed_in_1st_Quarter_After_Exit_Quarter,
Type_of_Employment_Match_1st_Quarter_After_Exit_Quarter, Earnings_1st_Quarter_After_Exit_Quarter,
Employed_in_2nd_Quarter_After_Exit_Quarter, Type_of_Employment_Match_2nd_Quarter_After_Exit_Quarter,
Earnings_2nd_Quarter_After_Exit_Quarter, Employed_in_3rd_Quarter_After_Exit_Quarter,
Type_of_Employment_Match_3rd_Quarter_After_Exit_Quarter, Earnings_3rd_Quarter_After_Exit_Quarter,
Employed_in_4th_Quarter_After_Exit_Quarter, Type_of_Employment_Match_4th_Quarter_After_Exit_Quarter,
Earnings_4th_Quarter_After_Exit_Quarter, Employment_Related_to_Training,
Retention_with_Same_Employer_2nd_Quarter_and_4th_Quarter, Type_of_Recognized_Credential_1,
Type_of_Recognized_Credential_2, Type_of_Recognized_Credential_3, Date_Attained_Recognized_Credential_1,
Date_Attained_Recognized_Credential_2, Date_Attained_Recognized_Credential_3,
Date_of_Most_Recent_Measurable_Skill_Gain_Educational_Functional_Level,
Date_of_Most_Recent_Measurable_Skill_Gain_Postsecondary_Transcript,
Date_of_Most_Recent_Measurable_Skill_Gain_Secondary_Transcript,
Date_of_Most_Recent_Measurable_Skill_Gain_Training_Milestone,
Date_of_Most_Recent_Measurable_Skill_Gain_Skills_Progression,
Date_Enrolled_in_Education_or_Training_Program_Leading_to_Credential_or_Employment,
Date_Completed_an_Education_or_Training_Program_Leading_to_Credential_or_Employment,
Date_Attained_Graduate_or_Post_Graduate_Degree)
WITH ctePirl (social_security_number, program_name, exit_date, Employed_in_1st_Quarter_After_Exit_Quarter,
Type_of_Employment_Match_1st_Quarter_After_Exit_Quarter, Earnings_1st_Quarter_After_Exit_Quarter,
Employed_in_2nd_Quarter_After_Exit_Quarter, Type_of_Employment_Match_2nd_Quarter_After_Exit_Quarter,
Earnings_2nd_Quarter_After_Exit_Quarter, Employed_in_3rd_Quarter_After_Exit_Quarter,
Type_of_Employment_Match_3rd_Quarter_After_Exit_Quarter, Earnings_3rd_Quarter_After_Exit_Quarter,
Employed_in_4th_Quarter_After_Exit_Quarter, Type_of_Employment_Match_4th_Quarter_After_Exit_Quarter,
Earnings_4th_Quarter_After_Exit_Quarter, Employment_Related_to_Training,
Retention_with_Same_Employer_2nd_Quarter_and_4th_Quarter, Type_of_Recognized_Credential_1,
Type_of_Recognized_Credential_2, Type_of_Recognized_Credential_3, Date_Attained_Recognized_Credential_1,
Date_Attained_Recognized_Credential_2, Date_Attained_Recognized_Credential_3,
Date_of_Most_Recent_Measurable_Skill_Gain_Educational_Functional_Level,
Date_of_Most_Recent_Measurable_Skill_Gain_Postsecondary_Transcript,
Date_of_Most_Recent_Measurable_Skill_Gain_Secondary_Transcript,
Date_of_Most_Recent_Measurable_Skill_Gain_Training_Milestone,
Date_of_Most_Recent_Measurable_Skill_Gain_Skills_Progression,
Date_Enrolled_in_Education_or_Training_Program_Leading_to_Credential_or_Employment,
Date_Completed_an_Education_or_Training_Program_Leading_to_Credential_or_Employment,
Date_Attained_Graduate_or_Post_Graduate_Degree)
AS
(
SELECT social_security_number,
CAST('Adult Education (WIOA)' AS VARCHAR(75)) AS program_name,
date_of_program_exit_wioa,
CASE
WHEN employed_in_1st_quarter_after_exit_quarter_wioa IN (1, 2, 3) THEN 'Yes'
ELSE 'No'
END,
CASE type_of_employment_match_1st_quarter_after_exit_quarter_wioa
WHEN 1 THEN 'UI Wage Data'
WHEN 2 THEN 'Federal Employment Records (OPM, USPS)'
WHEN 3 THEN 'Military Employment Records (DOD)'
WHEN 4 THEN 'Non UI verification'
WHEN 5 THEN 'Information not yet available'
WHEN 0 THEN 'Not employed'
ELSE ''
END,
COALESCE(earnings_1st_quarter_after_exit_quarter_wioa, 0),
CASE
WHEN employed_in_2nd_quarter_after_exit_quarter_wioa IN (1, 2, 3) THEN 'Yes'
ELSE 'No'
END,
CASE type_of_employment_match_2nd_quarter_after_exit_quarter_wioa
WHEN 1 THEN 'UI Wage Data'
WHEN 2 THEN 'Federal Employment Records (OPM, USPS)'
WHEN 3 THEN 'Military Employment Records (DOD)'
WHEN 4 THEN 'Non UI verification'
WHEN 5 THEN 'Information not yet available'
WHEN 0 THEN 'Not employed'
ELSE ''
END,
COALESCE(earnings_2nd_quarter_after_exit_quarter_wioa, 0),
CASE
WHEN employed_in_3rd_quarter_after_exit_quarter_wioa IN (1, 2, 3) THEN 'Yes'
ELSE 'No'
END,
CASE type_of_employment_match_3rd_quarter_after_exit_quarter_wioa
WHEN 1 THEN 'UI Wage Data'
WHEN 2 THEN 'Federal Employment Records (OPM, USPS)'
WHEN 3 THEN 'Military Employment Records (DOD)'
WHEN 4 THEN 'Non UI verification'
WHEN 5 THEN 'Information not yet available'
WHEN 0 THEN 'Not employed'
ELSE ''
END,
COALESCE(earnings_3rd_quarter_after_exit_quarter_wioa, 0),
CASE
WHEN employed_in_4th_quarter_after_exit_quarter_wioa IN (1, 2, 3) THEN 'Yes'
ELSE 'No'
END,
CASE type_of_employment_match_4th_quarter_after_exit_quarter_wioa
WHEN 1 THEN 'UI Wage Data'
WHEN 2 THEN 'Federal Employment Records (OPM, USPS)'
WHEN 3 THEN 'Military Employment Records (DOD)'
WHEN 4 THEN 'Non UI verification'
WHEN 5 THEN 'Information not yet available'
WHEN 0 THEN 'Not employed'
ELSE ''
END,
COALESCE(earnings_4th_quarter_after_exit_quarter_wioa, 0),
CASE employment_related_to_training_2nd_quarter_after_exit_wioa
WHEN 1 THEN 'Yes'
WHEN 0 THEN 'No'
ELSE ''
END,
CASE retention_with_the_same_employer_in_the_2nd_quarter_and_the_4th_quarter_wioa
WHEN 1 THEN 'Yes'
WHEN 0 THEN 'No'
ELSE ''
END,
CASE type_of_recognized_credential_wioa
WHEN 1 THEN 'Secondary School Diploma/or equivalency'
WHEN 2 THEN 'AA or AS Diploma/Degree'
WHEN 3 THEN 'BA or BS Diploma/Degree'
WHEN 4 THEN 'Occupational Licensure'
WHEN 5 THEN 'Occupational Certificate'
WHEN 6 THEN 'Occupational Certification'
WHEN 7 THEN 'Other Recognized Diploma, Degree, or Certificate'
WHEN 0 THEN 'No recognized credential'
ELSE ''
END,
CASE type_of_recognized_credential_2_wioa
WHEN 1 THEN 'Secondary School Diploma/or equivalency'
WHEN 2 THEN 'AA or AS Diploma/Degree'
WHEN 3 THEN 'BA or BS Diploma/Degree'
WHEN 4 THEN 'Occupational Licensure'
WHEN 5 THEN 'Occupational Certificate'
WHEN 6 THEN 'Occupational Certification'
WHEN 7 THEN 'Other Recognized Diploma, Degree, or Certificate'
WHEN 0 THEN 'No recognized credential'
ELSE ''
END,
CASE type_of_recognized_credential_3_wioa
WHEN 1 THEN 'Secondary School Diploma/or equivalency'
WHEN 2 THEN 'AA or AS Diploma/Degree'
WHEN 3 THEN 'BA or BS Diploma/Degree'
WHEN 4 THEN 'Occupational Licensure'
WHEN 5 THEN 'Occupational Certificate'
WHEN 6 THEN 'Occupational Certification'
WHEN 7 THEN 'Other Recognized Diploma, Degree, or Certificate'
WHEN 0 THEN 'No recognized credential'
ELSE ''
END,
COALESCE(date_attained_recognized_credential_wioa, CAST('9999-01-01' AS DATE)),
COALESCE(date_attained_recognized_credential_2_wioa, CAST('9999-01-01' AS DATE)),
COALESCE(date_attained_recognized_credential_3_wioa, CAST('9999-01-01' AS DATE)),
COALESCE(date_of_most_recent_measurable_skill_gains_educational_functioning_level_efl_wioa, CAST('9999-01-01' AS DATE)),
COALESCE(date_of_most_recent_measurable_skill_gains_postsecondary_transcript_report_card_wioa, CAST('9999-01-01' AS DATE)),
COALESCE(date_of_most_recent_measurable_skill_gains_secondary_transcript_report_card_wioa, CAST('9999-01-01' AS DATE)),
COALESCE(date_of_most_recent_measurable_skill_gains_training_milestone_wioa, CAST('9999-01-01' AS DATE)),
COALESCE(date_of_most_recent_measurable_skill_gains_skills_progression_wioa, CAST('9999-01-01' AS DATE)),
COALESCE(date_enrolled_in_post_exit_education_or_training_program_leading_to_a_recognized_postsecondary_credential_wioa, CAST('9999-01-01' AS DATE)),
COALESCE(date_completed_during_program_participation_an_education_or_training_program_leading_to_a_recognized_credential_or_employment, CAST('9999-01-01' AS DATE)),
COALESCE(date_attained_graduate_post_graduate_degree_wioa, CAST('9999-01-01' AS DATE))
FROM ds_ar_dws.pirl
WHERE DATEPART(year, date_of_program_exit_wioa) >= 2010
AND valid_ssn_format = 'Y'
AND pirl.adult_education_wioa = 1
),
cteFactData
AS
(
SELECT --Lookup Person Surrogate Key
(
SELECT DIM_Person.Person_Key
FROM DIM_Person
WHERE DIM_Person.Person_UID = pirl.social_security_number
) AS Person_Key,
--Lookup Program Surrogate Key
(
SELECT DIM_Program.Program_Key
FROM DIM_Program
WHERE DIM_Program.Program_Name = pirl.program_name
) AS Program_Key,
--Lookup Exit Year Quarter Surrogate Key
(
SELECT exit_qtr.Year_Quarter_Key
FROM DIM_Year_Quarter exit_qtr
WHERE pirl.exit_date between exit_qtr.quarter_start_date and exit_qtr.quarter_end_date
) AS Exit_Year_Quarter_Key,
pirl.Employed_in_1st_Quarter_After_Exit_Quarter,
pirl.Type_of_Employment_Match_1st_Quarter_After_Exit_Quarter,
pirl.Earnings_1st_Quarter_After_Exit_Quarter,
pirl.Employed_in_2nd_Quarter_After_Exit_Quarter,
pirl.Type_of_Employment_Match_2nd_Quarter_After_Exit_Quarter,
pirl.Earnings_2nd_Quarter_After_Exit_Quarter,
pirl.Employed_in_3rd_Quarter_After_Exit_Quarter,
pirl.Type_of_Employment_Match_3rd_Quarter_After_Exit_Quarter,
pirl.Earnings_3rd_Quarter_After_Exit_Quarter,
pirl.Employed_in_4th_Quarter_After_Exit_Quarter,
pirl.Type_of_Employment_Match_4th_Quarter_After_Exit_Quarter,
pirl.Earnings_4th_Quarter_After_Exit_Quarter,
pirl.Employment_Related_to_Training,
pirl.Retention_with_Same_Employer_2nd_Quarter_and_4th_Quarter,
pirl.Type_of_Recognized_Credential_1,
pirl.Type_of_Recognized_Credential_2,
pirl.Type_of_Recognized_Credential_3,
pirl.Date_Attained_Recognized_Credential_1,
pirl.Date_Attained_Recognized_Credential_2,
pirl.Date_Attained_Recognized_Credential_3,
pirl.Date_of_Most_Recent_Measurable_Skill_Gain_Educational_Functional_Level,
pirl.Date_of_Most_Recent_Measurable_Skill_Gain_Postsecondary_Transcript,
pirl.Date_of_Most_Recent_Measurable_Skill_Gain_Secondary_Transcript,
pirl.Date_of_Most_Recent_Measurable_Skill_Gain_Training_Milestone,
pirl.Date_of_Most_Recent_Measurable_Skill_Gain_Skills_Progression,
pirl.Date_Enrolled_in_Education_or_Training_Program_Leading_to_Credential_or_Employment,
pirl.Date_Completed_an_Education_or_Training_Program_Leading_to_Credential_or_Employment,
pirl.Date_Attained_Graduate_or_Post_Graduate_Degree
FROM ctePirl pirl
)
SELECT DISTINCT
COALESCE(Person_Key, 0),
COALESCE(Program_Key, 0),
COALESCE(Exit_Year_Quarter_Key, 0),
Employed_in_1st_Quarter_After_Exit_Quarter,
Type_of_Employment_Match_1st_Quarter_After_Exit_Quarter, Earnings_1st_Quarter_After_Exit_Quarter,
Employed_in_2nd_Quarter_After_Exit_Quarter, Type_of_Employment_Match_2nd_Quarter_After_Exit_Quarter,
Earnings_2nd_Quarter_After_Exit_Quarter, Employed_in_3rd_Quarter_After_Exit_Quarter,
Type_of_Employment_Match_3rd_Quarter_After_Exit_Quarter, Earnings_3rd_Quarter_After_Exit_Quarter,
Employed_in_4th_Quarter_After_Exit_Quarter, Type_of_Employment_Match_4th_Quarter_After_Exit_Quarter,
Earnings_4th_Quarter_After_Exit_Quarter, Employment_Related_to_Training,
Retention_with_Same_Employer_2nd_Quarter_and_4th_Quarter, Type_of_Recognized_Credential_1,
Type_of_Recognized_Credential_2, Type_of_Recognized_Credential_3, Date_Attained_Recognized_Credential_1,
Date_Attained_Recognized_Credential_2, Date_Attained_Recognized_Credential_3,
Date_of_Most_Recent_Measurable_Skill_Gain_Educational_Functional_Level,
Date_of_Most_Recent_Measurable_Skill_Gain_Postsecondary_Transcript,
Date_of_Most_Recent_Measurable_Skill_Gain_Secondary_Transcript,
Date_of_Most_Recent_Measurable_Skill_Gain_Training_Milestone,
Date_of_Most_Recent_Measurable_Skill_Gain_Skills_Progression,
Date_Enrolled_in_Education_or_Training_Program_Leading_to_Credential_or_Employment,
Date_Completed_an_Education_or_Training_Program_Leading_to_Credential_or_Employment,
Date_Attained_Graduate_or_Post_Graduate_Degree
FROM cteFactData;
```
#### Adult
```{sql}
/*
This script will load the the FACT_Person_Program_Outcome table with data for the "Adult (WIOA)" program.
Step 1
The data is collected from the source table (ds_ar_dws.pirl) and returned in the ctePIRL comment table expression (CTE).
Any reference values or boolean values are converted to text strings.
Step 2
The ctePirl data is then process thru the cteFactData CTE which looks up the dimension keys.
Step 3
The cteFactData is inserted into the fact table. Any keys that could not be found via the lookup are set to 0.
*/
-- FACT Person Program Outcome (PIRL - Adult)
INSERT INTO FACT_Person_Program_Outcome (Person_Key, Program_Key, Exit_Year_Quarter_Key, Employed_in_1st_Quarter_After_Exit_Quarter,
Type_of_Employment_Match_1st_Quarter_After_Exit_Quarter, Earnings_1st_Quarter_After_Exit_Quarter,
Employed_in_2nd_Quarter_After_Exit_Quarter, Type_of_Employment_Match_2nd_Quarter_After_Exit_Quarter,
Earnings_2nd_Quarter_After_Exit_Quarter, Employed_in_3rd_Quarter_After_Exit_Quarter,
Type_of_Employment_Match_3rd_Quarter_After_Exit_Quarter, Earnings_3rd_Quarter_After_Exit_Quarter,
Employed_in_4th_Quarter_After_Exit_Quarter, Type_of_Employment_Match_4th_Quarter_After_Exit_Quarter,
Earnings_4th_Quarter_After_Exit_Quarter, Employment_Related_to_Training,
Retention_with_Same_Employer_2nd_Quarter_and_4th_Quarter, Type_of_Recognized_Credential_1,
Type_of_Recognized_Credential_2, Type_of_Recognized_Credential_3, Date_Attained_Recognized_Credential_1,
Date_Attained_Recognized_Credential_2, Date_Attained_Recognized_Credential_3,
Date_of_Most_Recent_Measurable_Skill_Gain_Educational_Functional_Level,
Date_of_Most_Recent_Measurable_Skill_Gain_Postsecondary_Transcript,
Date_of_Most_Recent_Measurable_Skill_Gain_Secondary_Transcript,
Date_of_Most_Recent_Measurable_Skill_Gain_Training_Milestone,
Date_of_Most_Recent_Measurable_Skill_Gain_Skills_Progression,
Date_Enrolled_in_Education_or_Training_Program_Leading_to_Credential_or_Employment,
Date_Completed_an_Education_or_Training_Program_Leading_to_Credential_or_Employment,
Date_Attained_Graduate_or_Post_Graduate_Degree)
WITH ctePirl (social_security_number, program_name, exit_date, Employed_in_1st_Quarter_After_Exit_Quarter,
Type_of_Employment_Match_1st_Quarter_After_Exit_Quarter, Earnings_1st_Quarter_After_Exit_Quarter,
Employed_in_2nd_Quarter_After_Exit_Quarter, Type_of_Employment_Match_2nd_Quarter_After_Exit_Quarter,
Earnings_2nd_Quarter_After_Exit_Quarter, Employed_in_3rd_Quarter_After_Exit_Quarter,
Type_of_Employment_Match_3rd_Quarter_After_Exit_Quarter, Earnings_3rd_Quarter_After_Exit_Quarter,
Employed_in_4th_Quarter_After_Exit_Quarter, Type_of_Employment_Match_4th_Quarter_After_Exit_Quarter,
Earnings_4th_Quarter_After_Exit_Quarter, Employment_Related_to_Training,
Retention_with_Same_Employer_2nd_Quarter_and_4th_Quarter, Type_of_Recognized_Credential_1,
Type_of_Recognized_Credential_2, Type_of_Recognized_Credential_3, Date_Attained_Recognized_Credential_1,
Date_Attained_Recognized_Credential_2, Date_Attained_Recognized_Credential_3,
Date_of_Most_Recent_Measurable_Skill_Gain_Educational_Functional_Level,
Date_of_Most_Recent_Measurable_Skill_Gain_Postsecondary_Transcript,
Date_of_Most_Recent_Measurable_Skill_Gain_Secondary_Transcript,
Date_of_Most_Recent_Measurable_Skill_Gain_Training_Milestone,
Date_of_Most_Recent_Measurable_Skill_Gain_Skills_Progression,
Date_Enrolled_in_Education_or_Training_Program_Leading_to_Credential_or_Employment,
Date_Completed_an_Education_or_Training_Program_Leading_to_Credential_or_Employment,
Date_Attained_Graduate_or_Post_Graduate_Degree)
AS
(
SELECT social_security_number,
CAST('Adult (WIOA)' AS VARCHAR(75)) AS program_name,
date_of_program_exit_wioa,
CASE
WHEN employed_in_1st_quarter_after_exit_quarter_wioa IN (1, 2, 3) THEN 'Yes'
ELSE 'No'
END,
CASE type_of_employment_match_1st_quarter_after_exit_quarter_wioa
WHEN 1 THEN 'UI Wage Data'
WHEN 2 THEN 'Federal Employment Records (OPM, USPS)'
WHEN 3 THEN 'Military Employment Records (DOD)'
WHEN 4 THEN 'Non UI verification'
WHEN 5 THEN 'Information not yet available'
WHEN 0 THEN 'Not employed'
ELSE ''
END,
COALESCE(earnings_1st_quarter_after_exit_quarter_wioa, 0),
CASE
WHEN employed_in_2nd_quarter_after_exit_quarter_wioa IN (1, 2, 3) THEN 'Yes'
ELSE 'No'
END,
CASE type_of_employment_match_2nd_quarter_after_exit_quarter_wioa
WHEN 1 THEN 'UI Wage Data'
WHEN 2 THEN 'Federal Employment Records (OPM, USPS)'
WHEN 3 THEN 'Military Employment Records (DOD)'
WHEN 4 THEN 'Non UI verification'
WHEN 5 THEN 'Information not yet available'
WHEN 0 THEN 'Not employed'
ELSE ''
END,
COALESCE(earnings_2nd_quarter_after_exit_quarter_wioa, 0),
CASE
WHEN employed_in_3rd_quarter_after_exit_quarter_wioa IN (1, 2, 3) THEN 'Yes'
ELSE 'No'
END,
CASE type_of_employment_match_3rd_quarter_after_exit_quarter_wioa
WHEN 1 THEN 'UI Wage Data'
WHEN 2 THEN 'Federal Employment Records (OPM, USPS)'
WHEN 3 THEN 'Military Employment Records (DOD)'
WHEN 4 THEN 'Non UI verification'
WHEN 5 THEN 'Information not yet available'
WHEN 0 THEN 'Not employed'
ELSE ''
END,
COALESCE(earnings_3rd_quarter_after_exit_quarter_wioa, 0),
CASE
WHEN employed_in_4th_quarter_after_exit_quarter_wioa IN (1, 2, 3) THEN 'Yes'
ELSE 'No'