-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path8.DQ_Values_table.sql
77 lines (67 loc) · 2.06 KB
/
8.DQ_Values_table.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
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
---------------------------------------------------------------------------
-- Create LA_PBI_DQ_Values_Aggregated table
---------------------------------------------------------------------------
-------PRE-REQUISTIES--------
--1. Run create master table script
--------------------------------------------------------------------------
--Set the reporting period dates--
--------------------------------------------------------------------------
DECLARE @ReportingPeriodStartDate AS DATE = '2023-07-01'
DECLARE @ReportingPeriodEndDate AS DATE = '2024-06-30'
DECLARE @SubmissionsAsOfDate AS DATE = GETDATE()
--------------------------------------------------------------------------
--Call the procedure which generates the data quality values --
--------------------------------------------------------------------------
-- Create a temporary table to store the master table record IDs
DROP TABLE IF EXISTS #RecordIDs;
SELECT Der_Unique_Record_ID
INTO #RecordIDs
FROM ASC_Sandbox.LA_PBI_Master_Table
EXEC ASC_Sandbox.GetDQValues @InputTable = '#RecordIDs',
@OutputDQTable = 'ASC_Sandbox.LA_PBI_DQ_Values_Aggregated_tmp'
--------------------------------------------------------------------------
-- Aggregate up to LA and National level --
--------------------------------------------------------------------------
DROP TABLE IF EXISTS ASC_Sandbox.LA_PBI_DQ_Values_Aggregated;
SELECT
LA_Name,
LA_Code,
Module,
DataField,
FieldStatus,
FieldValidity,
[Value],
Sum(Count) AS Count
INTO ASC_Sandbox.LA_PBI_DQ_Values_Aggregated
FROM (
SELECT
'England' AS 'LA_Name',
'99999' AS 'LA_Code',
Module,
DataField,
FieldStatus,
FieldValidity,
NULL AS 'Value',
Count
FROM ASC_Sandbox.LA_PBI_DQ_Values_Aggregated_tmp dq
UNION ALL
SELECT
LA_Name,
LA_Code,
Module,
DataField,
FieldStatus,
FieldValidity,
[Value],
Count
FROM ASC_Sandbox.LA_PBI_DQ_Values_Aggregated_tmp
) a
GROUP BY
LA_Name,
LA_Code,
Module,
DataField,
FieldStatus,
FieldValidity,
[Value]
DROP TABLE ASC_Sandbox.LA_PBI_DQ_Values_Aggregated_tmp;