Skip to content

Commit

Permalink
AA L7 fix
Browse files Browse the repository at this point in the history
  • Loading branch information
robjharrison committed Jul 30, 2024
1 parent bdbe38a commit f1ae4af
Show file tree
Hide file tree
Showing 3 changed files with 2,247 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ GO

DECLARE @Run_SSD_As_Temporary_Tables BIT;
SET @Run_SSD_As_Temporary_Tables = 0; -- 1==Single use SSD extract uses tempdb..# | 0==Persistent SSD table set up

DECLARE @sql NVARCHAR(MAX) = N''; -- used in both clean-up and logging
DECLARE @schema_name NVARCHAR(128) = N'ssd_development'; -- Set your schema name here. Leave empty for default behaviour
DECLARE @default_schema NVARCHAR(128) = N'dbo'; -- Default schema if none provided


SET NOCOUNT ON;
Expand Down Expand Up @@ -98,9 +101,6 @@ BEGIN

-- pre-emptively avoid any run-time conflicts from left-behind FK constraints

DECLARE @schema_name NVARCHAR(128) = N'ssd_development'; -- Set your schema name here. Leave empty for default behaviour
DECLARE @default_schema NVARCHAR(128) = N'dbo'; -- Default schema if none provided
DECLARE @sql NVARCHAR(MAX);

-- Set schema name to default if not provided
IF @schema_name = N'' OR @schema_name IS NULL
Expand Down Expand Up @@ -3138,8 +3138,7 @@ INSERT INTO ssd_development.ssd_cla_reviews (
clar_cla_review_date,
clar_cla_review_cancelled,
clar_cla_review_participation
)

)
SELECT
fcr.FACT_CLA_REVIEW_ID AS clar_cla_review_id,
fcr.FACT_CLA_ID AS clar_cla_id,
Expand Down Expand Up @@ -4533,11 +4532,15 @@ PRINT 'Table created: ' + @TableName;
Object Name: ssd_involvements
Description:
Author: D2I
Version: 1.1
Version: 1.2:
1.1: Revisions to 1.0/0.9. DEPT_ID else .._HISTORY_DEPARTMENT_ID 300724 RH
1.0: Trancated professional_team field IF comment data populates 110624 RH
0.9: added person_id and changed source of professional_team 090424 JH
Status: [R]elease
Remarks: Regarding the increased size/len on invo_professional_team
Remarks: v1.2 revisions backtrack prev changes in favour of dept/hist ID fields
[TESTING] The below towards v1.0 for ref. only
Regarding the increased size/len on invo_professional_team
The (truncated)COMMENTS field is only used if:
WORKER_HISTORY_DEPARTMENT_DESC is NULL.
DEPARTMENT_NAME is NULL.
Expand Down Expand Up @@ -4604,12 +4607,14 @@ SELECT
-- THEN fi.COMMENTS
-- END -- if fi.COMMENTS is NULL, results in NULL
-- ), 255) AS invo_professional_team,

CASE
-- replacing the above and...
-- replace admin -1 values for when no worker associated [TESTING] #DtoI-1762
WHEN fi.FACT_WORKER_HISTORY_DEPARTMENT_ID = -1 THEN NULL
ELSE fi.FACT_WORKER_HISTORY_DEPARTMENT_ID
WHEN fi.DIM_DEPARTMENT_ID IS NOT NULL AND fi.DIM_DEPARTMENT_ID != -1 THEN fi.DIM_DEPARTMENT_ID
ELSE CASE
-- replace system -1 values for when no worker associated [TESTING] #DtoI-1762
WHEN fi.FACT_WORKER_HISTORY_DEPARTMENT_ID = -1 THEN NULL
ELSE fi.FACT_WORKER_HISTORY_DEPARTMENT_ID
END
END AS invo_professional_team,
fi.DIM_PERSON_ID AS invo_person_id,
fi.START_DTTM AS invo_involvement_start_date,
Expand Down Expand Up @@ -5566,7 +5571,6 @@ DECLARE @pk_datatype NVARCHAR(255);
DECLARE @additional_detail NVARCHAR(MAX);
DECLARE @error_message NVARCHAR(MAX);
DECLARE @table_name NVARCHAR(255);
DECLARE @schema_name NVARCHAR(255) = N'ssd_development'; -- Placeholder schema name for all tables <OR> empty string
-- DECLARE @schema_name NVARCHAR(255) = N''; -- Placeholder schema name for all tables <OR> empty string


Expand Down
38 changes: 18 additions & 20 deletions tools-ssd_dfe_returns/AnnexA_sqlserver.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1240,28 +1240,26 @@ FROM
AND cp.cppl_cp_plan_id = vis.CPRegID
AND vis.Rnk = 1

-- get latest review
-- Get latest review
LEFT JOIN
(
SELECT
cp.cppl_person_id PersonID,
cp.cppl_cp_plan_id CPRegID,
-- MAX(rev.cppr_cp_review_date) ReviewDate
ROW_NUMBER() OVER(PARTITION BY clap.clap_person_id ORDER BY rev.clar_cla_review_date DESC) AS Rnk
(
SELECT
cp.cppl_person_id AS PersonID,
cp.cppl_cp_plan_id AS CPRegID,
ROW_NUMBER() OVER (PARTITION BY cp.cppl_person_id, cp.cppl_cp_plan_id ORDER BY rev.cppr_cp_review_date DESC) AS Rnk,
rev.cppr_cp_review_date AS ReviewDate
FROM
ssd_development.ssd_cp_plans cp
INNER JOIN
ssd_development.ssd_cp_reviews rev ON cp.cppl_person_id = rev.cppr_person_id
AND cp.cppl_cp_plan_id = rev.cppr_cp_plan_id
AND rev.cppr_cp_review_date BETWEEN cp.cppl_cp_plan_start_date AND COALESCE(cp.cppl_cp_plan_end_date, GETDATE())
WHERE
COALESCE(cp.cppl_cp_plan_end_date, '99991231') >= DATEADD(MONTH, -@AA_ReportingPeriod, GETDATE())
) AS rev ON cp.cppl_person_id = rev.PersonID
AND cp.cppl_cp_plan_id = rev.CPRegID
AND rev.Rnk = 1

FROM
ssd_development.ssd_cp_plans cp
INNER JOIN
ssd_cp_reviews rev ON cp.cppl_person_id = rev.cppr_person_id
AND cp.cppl_cp_plan_id = rev.cppr_cp_plan_id
AND rev.cppr_cp_review_date between cp.cppl_cp_plan_start_date and COALESCE(cp.cppl_cp_plan_end_date, GETDATE())
WHERE
COALESCE(cp.cppl_cp_plan_end_date, '99991231') >= DATEADD(MONTH, -@AA_ReportingPeriod, GETDATE())
GROUP BY
cp.cppl_person_id,
cp.cppl_cp_plan_id
) AS rev on cp.cppl_person_id = rev.PersonID
AND cp.cppl_cp_plan_id = rev.CPRegID

-- get whether child subject to Emergency Protection Order or Protected Under Police Powers in Last Six Months
LEFT JOIN
Expand Down
Loading

0 comments on commit f1ae4af

Please sign in to comment.