diff --git a/inst/sql/sql_server/analyses/2004.sql b/inst/sql/sql_server/analyses/2004.sql index f3fb5d8b..e43360db 100644 --- a/inst/sql/sql_server/analyses/2004.sql +++ b/inst/sql/sql_server/analyses/2004.sql @@ -1,6 +1,8 @@ -- Analysis 2004: Number of distinct patients that overlap between specific domains -- Bit String Breakdown: 1) Condition Occurrence 2) Drug Exposure 3) Device Exposure 4) Measurement 5) Death 6) Procedure Occurrence 7) Observation + + select distinct person_id into #conoc from @cdmDatabaseSchema.condition_occurrence; select distinct person_id into #drexp from @cdmDatabaseSchema.drug_exposure; select distinct person_id into #dvexp from @cdmDatabaseSchema.device_exposure; @@ -8,8 +10,19 @@ select distinct person_id into #msmt from @cdmDatabaseSchema.measurement; select distinct person_id into #death from @cdmDatabaseSchema.death; select distinct person_id into #prococ from @cdmDatabaseSchema.procedure_occurrence; select distinct person_id into #obs from @cdmDatabaseSchema.observation; +select count(distinct(person_id)) as totalPersons into #totPers from @cdmDatabaseSchema.person; + +create table @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 ( + analysis_id int, + stratum_1 varchar(255), + stratum_2 varchar(255), + stratum_3 varchar(255), + stratum_4 varchar(255), + stratum_5 varchar(255), + count_value int +); -with rawData as ( +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('0000001' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -17,10 +30,15 @@ select 2004 as analysis_id, CAST(NULL AS VARCHAR(255)) as stratum_4, CAST(NULL AS VARCHAR(255)) as stratum_5, personIntersection.count_value - from - (select count(*) as count_value from(select person_id from #obs) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL -select 2004 as analysis_id, + from ( + select count(*) as count_value from ( + select person_id from #obs + ) subquery + ) personIntersection, + (select totalPersons from #totPers) totalPersonsDb -- estimated cost >~ 1% of the complete query +; + +insert into #tmpach_2004 select 2004 as analysis_id, CAST('0000010' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, CAST(NULL AS VARCHAR(255)) as stratum_3, @@ -29,7 +47,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #prococ) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('0000011' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -39,7 +60,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #prococ intersect select person_id from #obs) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('0000100' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -49,7 +73,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #death) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('0000101' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -59,7 +86,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #death intersect select person_id from #obs) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('0000110' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -69,7 +99,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #death intersect select person_id from #prococ) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('0000111' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -79,7 +112,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #death intersect select person_id from #prococ intersect select person_id from #obs) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('0001000' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -89,7 +125,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #msmt) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('0001001' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -99,7 +138,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #msmt intersect select person_id from #obs) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('0001010' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -109,7 +151,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #msmt intersect select person_id from #prococ) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('0001011' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -119,7 +164,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #msmt intersect select person_id from #prococ intersect select person_id from #obs) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('0001100' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -129,7 +177,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #msmt intersect select person_id from #death) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('0001101' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -139,7 +190,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #msmt intersect select person_id from #death intersect select person_id from #obs) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('0001110' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -149,7 +203,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #msmt intersect select person_id from #death intersect select person_id from #prococ) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('0001111' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -159,7 +216,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #msmt intersect select person_id from #death intersect select person_id from #prococ intersect select person_id from #obs) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('0010000' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -169,7 +229,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #dvexp) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('0010001' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -179,7 +242,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #dvexp intersect select person_id from #obs) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('0010010' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -189,7 +255,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #dvexp intersect select person_id from #prococ) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('0010011' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -199,7 +268,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #dvexp intersect select person_id from #prococ intersect select person_id from #obs) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('0010100' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -209,7 +281,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #dvexp intersect select person_id from #death) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('0010101' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -219,7 +294,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #dvexp intersect select person_id from #death intersect select person_id from #obs) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('0010110' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -229,7 +307,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #dvexp intersect select person_id from #death intersect select person_id from #prococ) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('0010111' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -239,7 +320,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #dvexp intersect select person_id from #death intersect select person_id from #prococ intersect select person_id from #obs) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('0011000' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -249,7 +333,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #dvexp intersect select person_id from #msmt) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('0011001' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -259,7 +346,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #dvexp intersect select person_id from #msmt intersect select person_id from #obs) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('0011010' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -269,7 +359,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #dvexp intersect select person_id from #msmt intersect select person_id from #prococ) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('0011011' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -279,7 +372,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #dvexp intersect select person_id from #msmt intersect select person_id from #prococ intersect select person_id from #obs) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('0011100' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -289,7 +385,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #dvexp intersect select person_id from #msmt intersect select person_id from #death) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('0011101' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -299,7 +398,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #dvexp intersect select person_id from #msmt intersect select person_id from #death intersect select person_id from #obs) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('0011110' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -309,7 +411,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #dvexp intersect select person_id from #msmt intersect select person_id from #death intersect select person_id from #prococ) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('0011111' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -319,7 +424,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #dvexp intersect select person_id from #msmt intersect select person_id from #death intersect select person_id from #prococ intersect select person_id from #obs) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('0100000' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -329,7 +437,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #drexp) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('0100001' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -339,7 +450,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #drexp intersect select person_id from #obs) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('0100010' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -349,7 +463,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #drexp intersect select person_id from #prococ) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('0100011' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -359,7 +476,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #drexp intersect select person_id from #prococ intersect select person_id from #obs) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('0100100' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -369,7 +489,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #drexp intersect select person_id from #death) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('0100101' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -379,7 +502,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #drexp intersect select person_id from #death intersect select person_id from #obs) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('0100110' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -389,7 +515,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #drexp intersect select person_id from #death intersect select person_id from #prococ) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('0100111' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -399,7 +528,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #drexp intersect select person_id from #death intersect select person_id from #prococ intersect select person_id from #obs) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('0101000' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -409,7 +541,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #drexp intersect select person_id from #msmt) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('0101001' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -419,7 +554,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #drexp intersect select person_id from #msmt intersect select person_id from #obs) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('0101010' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -429,7 +567,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #drexp intersect select person_id from #msmt intersect select person_id from #prococ) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('0101011' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -439,7 +580,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #drexp intersect select person_id from #msmt intersect select person_id from #prococ intersect select person_id from #obs) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('0101100' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -449,7 +593,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #drexp intersect select person_id from #msmt intersect select person_id from #death) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('0101101' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -459,7 +606,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #drexp intersect select person_id from #msmt intersect select person_id from #death intersect select person_id from #obs) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('0101110' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -469,7 +619,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #drexp intersect select person_id from #msmt intersect select person_id from #death intersect select person_id from #prococ) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('0101111' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -479,7 +632,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #drexp intersect select person_id from #msmt intersect select person_id from #death intersect select person_id from #prococ intersect select person_id from #obs) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('0110000' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -489,7 +645,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #drexp intersect select person_id from #dvexp) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('0110001' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -499,7 +658,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #drexp intersect select person_id from #dvexp intersect select person_id from #obs) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('0110010' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -509,7 +671,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #drexp intersect select person_id from #dvexp intersect select person_id from #prococ) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('0110011' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -519,7 +684,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #drexp intersect select person_id from #dvexp intersect select person_id from #prococ intersect select person_id from #obs) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('0110100' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -529,7 +697,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #drexp intersect select person_id from #dvexp intersect select person_id from #death) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('0110101' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -539,7 +710,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #drexp intersect select person_id from #dvexp intersect select person_id from #death intersect select person_id from #obs) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('0110110' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -549,7 +723,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #drexp intersect select person_id from #dvexp intersect select person_id from #death intersect select person_id from #prococ) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('0110111' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -559,7 +736,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #drexp intersect select person_id from #dvexp intersect select person_id from #death intersect select person_id from #prococ intersect select person_id from #obs) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('0111000' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -569,7 +749,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #drexp intersect select person_id from #dvexp intersect select person_id from #msmt) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('0111001' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -579,7 +762,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #drexp intersect select person_id from #dvexp intersect select person_id from #msmt intersect select person_id from #obs) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('0111010' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -589,7 +775,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #drexp intersect select person_id from #dvexp intersect select person_id from #msmt intersect select person_id from #prococ) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('0111011' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -599,7 +788,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #drexp intersect select person_id from #dvexp intersect select person_id from #msmt intersect select person_id from #prococ intersect select person_id from #obs) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('0111100' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -609,7 +801,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #drexp intersect select person_id from #dvexp intersect select person_id from #msmt intersect select person_id from #death) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('0111101' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -619,7 +814,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #drexp intersect select person_id from #dvexp intersect select person_id from #msmt intersect select person_id from #death intersect select person_id from #obs) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('0111110' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -629,7 +827,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #drexp intersect select person_id from #dvexp intersect select person_id from #msmt intersect select person_id from #death intersect select person_id from #prococ) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('0111111' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -639,7 +840,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #drexp intersect select person_id from #dvexp intersect select person_id from #msmt intersect select person_id from #death intersect select person_id from #prococ intersect select person_id from #obs) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('1000000' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -649,7 +853,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #conoc) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('1000001' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -659,7 +866,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #conoc intersect select person_id from #obs) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('1000010' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -669,7 +879,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #conoc intersect select person_id from #prococ) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('1000011' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -679,7 +892,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #conoc intersect select person_id from #prococ intersect select person_id from #obs) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('1000100' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -689,7 +905,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #conoc intersect select person_id from #death) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('1000101' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -699,7 +918,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #conoc intersect select person_id from #death intersect select person_id from #obs) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('1000110' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -709,7 +931,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #conoc intersect select person_id from #death intersect select person_id from #prococ) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('1000111' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -719,7 +944,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #conoc intersect select person_id from #death intersect select person_id from #prococ intersect select person_id from #obs) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('1001000' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -729,7 +957,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #conoc intersect select person_id from #msmt) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('1001001' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -739,7 +970,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #conoc intersect select person_id from #msmt intersect select person_id from #obs) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('1001010' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -749,7 +983,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #conoc intersect select person_id from #msmt intersect select person_id from #prococ) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('1001011' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -759,7 +996,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #conoc intersect select person_id from #msmt intersect select person_id from #prococ intersect select person_id from #obs) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('1001100' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -769,7 +1009,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #conoc intersect select person_id from #msmt intersect select person_id from #death) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('1001101' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -779,7 +1022,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #conoc intersect select person_id from #msmt intersect select person_id from #death intersect select person_id from #obs) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('1001110' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -789,7 +1035,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #conoc intersect select person_id from #msmt intersect select person_id from #death intersect select person_id from #prococ) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('1001111' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -799,7 +1048,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #conoc intersect select person_id from #msmt intersect select person_id from #death intersect select person_id from #prococ intersect select person_id from #obs) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('1010000' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -809,7 +1061,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #conoc intersect select person_id from #dvexp) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('1010001' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -819,7 +1074,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #conoc intersect select person_id from #dvexp intersect select person_id from #obs) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('1010010' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -829,7 +1087,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #conoc intersect select person_id from #dvexp intersect select person_id from #prococ) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('1010011' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -839,7 +1100,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #conoc intersect select person_id from #dvexp intersect select person_id from #prococ intersect select person_id from #obs) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('1010100' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -849,7 +1113,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #conoc intersect select person_id from #dvexp intersect select person_id from #death) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('1010101' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -859,7 +1126,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #conoc intersect select person_id from #dvexp intersect select person_id from #death intersect select person_id from #obs) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('1010110' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -869,7 +1139,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #conoc intersect select person_id from #dvexp intersect select person_id from #death intersect select person_id from #prococ) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('1010111' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -879,7 +1152,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #conoc intersect select person_id from #dvexp intersect select person_id from #death intersect select person_id from #prococ intersect select person_id from #obs) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('1011000' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -889,7 +1165,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #conoc intersect select person_id from #dvexp intersect select person_id from #msmt) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('1011001' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -899,7 +1178,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #conoc intersect select person_id from #dvexp intersect select person_id from #msmt intersect select person_id from #obs) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('1011010' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -909,7 +1191,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #conoc intersect select person_id from #dvexp intersect select person_id from #msmt intersect select person_id from #prococ) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('1011011' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -919,7 +1204,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #conoc intersect select person_id from #dvexp intersect select person_id from #msmt intersect select person_id from #prococ intersect select person_id from #obs) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('1011100' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -929,7 +1217,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #conoc intersect select person_id from #dvexp intersect select person_id from #msmt intersect select person_id from #death) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('1011101' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -939,7 +1230,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #conoc intersect select person_id from #dvexp intersect select person_id from #msmt intersect select person_id from #death intersect select person_id from #obs) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('1011110' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -949,7 +1243,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #conoc intersect select person_id from #dvexp intersect select person_id from #msmt intersect select person_id from #death intersect select person_id from #prococ) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('1011111' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -959,7 +1256,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #conoc intersect select person_id from #dvexp intersect select person_id from #msmt intersect select person_id from #death intersect select person_id from #prococ intersect select person_id from #obs) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('1100000' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -969,7 +1269,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #conoc intersect select person_id from #drexp) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('1100001' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -979,7 +1282,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #conoc intersect select person_id from #drexp intersect select person_id from #obs) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('1100010' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -989,7 +1295,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #conoc intersect select person_id from #drexp intersect select person_id from #prococ) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('1100011' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -999,7 +1308,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #conoc intersect select person_id from #drexp intersect select person_id from #prococ intersect select person_id from #obs) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('1100100' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -1009,7 +1321,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #conoc intersect select person_id from #drexp intersect select person_id from #death) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('1100101' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -1019,7 +1334,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #conoc intersect select person_id from #drexp intersect select person_id from #death intersect select person_id from #obs) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('1100110' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -1029,7 +1347,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #conoc intersect select person_id from #drexp intersect select person_id from #death intersect select person_id from #prococ) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('1100111' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -1039,7 +1360,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #conoc intersect select person_id from #drexp intersect select person_id from #death intersect select person_id from #prococ intersect select person_id from #obs) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('1101000' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -1049,7 +1373,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #conoc intersect select person_id from #drexp intersect select person_id from #msmt) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('1101001' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -1059,7 +1386,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #conoc intersect select person_id from #drexp intersect select person_id from #msmt intersect select person_id from #obs) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('1101010' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -1069,7 +1399,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #conoc intersect select person_id from #drexp intersect select person_id from #msmt intersect select person_id from #prococ) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('1101011' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -1079,7 +1412,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #conoc intersect select person_id from #drexp intersect select person_id from #msmt intersect select person_id from #prococ intersect select person_id from #obs) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('1101100' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -1089,7 +1425,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #conoc intersect select person_id from #drexp intersect select person_id from #msmt intersect select person_id from #death) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('1101101' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -1099,7 +1438,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #conoc intersect select person_id from #drexp intersect select person_id from #msmt intersect select person_id from #death intersect select person_id from #obs) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('1101110' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -1109,7 +1451,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #conoc intersect select person_id from #drexp intersect select person_id from #msmt intersect select person_id from #death intersect select person_id from #prococ) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('1101111' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -1119,7 +1464,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #conoc intersect select person_id from #drexp intersect select person_id from #msmt intersect select person_id from #death intersect select person_id from #prococ intersect select person_id from #obs) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('1110000' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -1129,7 +1477,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #conoc intersect select person_id from #drexp intersect select person_id from #dvexp) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('1110001' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -1139,7 +1490,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #conoc intersect select person_id from #drexp intersect select person_id from #dvexp intersect select person_id from #obs) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('1110010' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -1149,7 +1503,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #conoc intersect select person_id from #drexp intersect select person_id from #dvexp intersect select person_id from #prococ) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('1110011' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -1159,7 +1516,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #conoc intersect select person_id from #drexp intersect select person_id from #dvexp intersect select person_id from #prococ intersect select person_id from #obs) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('1110100' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -1169,7 +1529,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #conoc intersect select person_id from #drexp intersect select person_id from #dvexp intersect select person_id from #death) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('1110101' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -1179,7 +1542,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #conoc intersect select person_id from #drexp intersect select person_id from #dvexp intersect select person_id from #death intersect select person_id from #obs) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('1110110' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -1189,7 +1555,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #conoc intersect select person_id from #drexp intersect select person_id from #dvexp intersect select person_id from #death intersect select person_id from #prococ) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('1110111' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -1199,7 +1568,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #conoc intersect select person_id from #drexp intersect select person_id from #dvexp intersect select person_id from #death intersect select person_id from #prococ intersect select person_id from #obs) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('1111000' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -1209,7 +1581,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #conoc intersect select person_id from #drexp intersect select person_id from #dvexp intersect select person_id from #msmt) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('1111001' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -1219,7 +1594,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #conoc intersect select person_id from #drexp intersect select person_id from #dvexp intersect select person_id from #msmt intersect select person_id from #obs) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('1111010' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -1229,7 +1607,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #conoc intersect select person_id from #drexp intersect select person_id from #dvexp intersect select person_id from #msmt intersect select person_id from #prococ) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('1111011' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -1239,7 +1620,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #conoc intersect select person_id from #drexp intersect select person_id from #dvexp intersect select person_id from #msmt intersect select person_id from #prococ intersect select person_id from #obs) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('1111100' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -1249,7 +1633,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #conoc intersect select person_id from #drexp intersect select person_id from #dvexp intersect select person_id from #msmt intersect select person_id from #death) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('1111101' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -1259,7 +1646,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #conoc intersect select person_id from #drexp intersect select person_id from #dvexp intersect select person_id from #msmt intersect select person_id from #death intersect select person_id from #obs) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('1111110' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -1269,7 +1659,10 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #conoc intersect select person_id from #drexp intersect select person_id from #dvexp intersect select person_id from #msmt intersect select person_id from #death intersect select person_id from #prococ) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) totalPersonsDb UNION ALL + (select totalPersons from #totPers) totalPersonsDb +; + +insert into @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 select 2004 as analysis_id, CAST('1111111' AS VARCHAR(255)) as stratum_1, cast((1.0 * personIntersection.count_value / totalPersonsDb.totalPersons) as varchar(255)) as stratum_2, @@ -1279,7 +1672,8 @@ select 2004 as analysis_id, personIntersection.count_value from (select count(*) as count_value from(select person_id from #conoc intersect select person_id from #drexp intersect select person_id from #dvexp intersect select person_id from #msmt intersect select person_id from #death intersect select person_id from #prococ intersect select person_id from #obs) subquery) personIntersection, - (select count(distinct(person_id)) as totalPersons from @cdmDatabaseSchema.person) as totalPersonsDb) select * INTO @scratchDatabaseSchema@schemaDelim@tempAchillesPrefix_2004 from rawData; + (select totalPersons from #totPers) as totalPersonsDb; + drop table #conoc; drop table #drexp; @@ -1288,3 +1682,4 @@ drop table #msmt; drop table #death; drop table #prococ; drop table #obs; +drop table #totPers; \ No newline at end of file