SELECT DISTINCT [State Name], TstNum, 1 as Grp, 0 as lvl, 0 as lvl1, "Grouping Title for Sub-report 1:" as GrpHdr, null as IDCode, null as JName, null as GType, null as EFGAmt from ABCD_E_with_coterminus_EFG
UNION SELECT DISTINCT [State Name], TstNum, 1, 0, 1 ,null, "IDCode", "Jurisdiction Name", "Geography Type", "EFG Amount" FROM ABCD_E_with_coterminus_EFG
UNION SELECT [State Name], TstNum, 1, 1, 0, null, IIf([LMNOKEY]='339011',[LMNOKEY] & "*",[LMNOKEY]), LMNONAME, IIf([LMNO_TY]='61','Urban County','Metro City'), "$" & EFGAmount from ABCD_E_with_coterminus_EFG
UNION SELECT [State Name], TstNum, 1, 2, 0, null, "Total",null, null, "$" & sum(efgAmount) from ABCD_E_with_coterminus_EFG GROUP BY [State Name], TstNum
UNION SELECT DISTINCT [State Name], TstNum, 1, 2, 1, null, null, null, null, null from ABCD_E_with_coterminus_EFG
UNION SELECT DISTINCT [State Name], TstNum, 2 as Grp, 0 as lvl, 0 as lvl1, "Grouping Title for Sub-report 2:" as GrpHdr, null as IDCode, null as JName, null as GType, null as EFGAmt from ABCD_with_EFG_bounced_to_ST
UNION SELECT DISTINCT [State Name], TstNum, 2, 0, 1, null, "IDCode", "Jurisdiction Name", null, "EFG Amount" FROM ABCD_with_EFG_bounced_to_ST
UNION SELECT [State Name], TstNum, 2, 1 ,0, null, IIf([NameKEY]='339011',[NameKEY] & "*",[NameKEY]), GeoNAME, null, "$" & [EFG Amount] from ABCD_with_EFG_bounced_to_ST
UNION SELECT [State Name], TstNum, 2, 2, 0, null, "Total", null, null,"$" & sum([efg Amount]) from ABCD_with_EFG_bounced_to_ST GROUP BY [State Name], TstNum
UNION SELECT DISTINCT [State Name], TstNum, 2, 2, 1, null, null, null, null, null from ABCD_with_EFG_bounced_to_ST
UNION SELECT DISTINCT [State Name], TstNum, 3 as Grp, 0 as lvl, 0, "Grouping Title for Sub-report 3:" as GrpHdr, null as IDCode, null as JName, null as GType, null as EFGAmt from ABCD_UC_EFG_bounce_to_state
UNION SELECT DISTINCT [State Name], TstNum, 3, 0, 1, null, "IDCode", "Jurisdiction Name", null, "EFG Amount" FROM ABCD_UC_EFG_bounce_to_state
UNION SELECT [State Name], TstNum, 3, 1, 0, null, IIf([NameKEY]='339011',[NameKEY] & "*",[NameKEY]), GeoNAME, null, "$" & [EFG Amount] from ABCD_UC_EFG_bounce_to_state
UNION SELECT [State Name], TstNum,3, 2, 0, null, "Total", null, null, "$" & sum([efg Amount]) from ABCD_UC_EFG_bounce_to_state GROUP BY [State Name], TstNum
UNION SELECT DISTINCT [State Name], TstNum, 3, 2, 1, null, null, null, null, null from ABCD_UC_EFG_bounce_to_state
UNION SELECT DISTINCT [State Name], TstNum, 4 as Grp, 0 as lvl, 0, "Grouping Title for Sub-report 4:" as GrpHdr, null as IDCode, null as JName, null as GType, null as EFGAmt from NE_counties_with_EFG_bounce
UNION SELECT DISTINCT [State Name], TstNum, 4, 0, 1, null, "IDCode", "Jurisdiction Name", null, "EFG Amount" FROM NE_counties_with_EFG_bounce
UNION SELECT [State Name], TstNum, 4, 1, 0, null, IIf([NameKEY]='339011',[NameKEY] & "*",[NameKEY]), GeoNAME, null, "$" & [EFG Amount] from NE_counties_with_EFG_bounce
UNION SELECT [State Name], TstNum,4, 2, 0, null, "Total", null, null,"$" & sum([efg Amount]) from NE_counties_with_EFG_bounce GROUP BY [State Name], TstNum
UNION SELECT DISTINCT [State Name], TstNum, 4, 2, 1, null, null, null, null, null from NE_counties_with_EFG_bounce
UNION SELECT DISTINCT [State Name], TstNum, 5 as Grp, 0 as lvl, 0, "Grouping Title for Sub-report 5:" as GrpHdr, null as IDCode, null as JName, null as GType, null as EFGAmt from LMNO_NE_with_EFG_Bounce
UNION SELECT DISTINCT [State Name], TstNum, 5, 0, 1,null, "IDCode", "Jurisdiction Name", null, "EFG Amount" FROM LMNO_NE_with_EFG_Bounce
UNION SELECT [State Name], TstNum, 5, 1, 0, null, IIf([NameKEY]='9999',[NameKEY] & "*",[NameKEY]), GeoNAME, null, "$" & [EFGAmount] from LMNO_NE_with_EFG_Bounce
UNION SELECT [State Name], TstNum,5, 2, 0, null, "Total", null, null, "$" & sum([efgAmount]) from LMNO_NE_with_EFG_Bounce GROUP BY [State Name], TstNum
UNION SELECT DISTINCT [State Name], TstNum, 5, 2, 1, null, null, null, null, null from LMNO_NE_with_EFG_Bounce
UNION SELECT DISTINCT [State Name], TstNum, 6 as Grp, 0 as lvl, 0, "Grouping Title for Sub-report 6:" as GrpHdr, null as IDCode, null as JName, null as GType, null as EFGAmt from LMNO_UC_with_EFG_to_UC
UNION SELECT DISTINCT [State Name], TstNum, 6, 0, 1, null, "IDCode", "Jurisdiction Name", null, "EFG Amount" FROM LMNO_UC_with_EFG_to_UC
UNION SELECT [State Name], TstNum, 6, 1, 0, null, IIf([NameKEY]='339011',[NameKEY] & "*",[NameKEY]), GeoNAME, null, "$" & [EFG Amount] from LMNO_UC_with_EFG_to_UC
UNION SELECT [State Name], TstNum, 6, 2, 0, null, "Total", null, null, "$" & sum([efg Amount]) from LMNO_UC_with_EFG_to_UC GROUP BY [State Name], TstNum
UNION SELECT DISTINCT [State Name], TstNum, 6, 2, 1, null, null, null, null, null from LMNO_UC_with_EFG_to_UC;