Generate Documentation
CIIDCIID-ReportsG3GitHub
  • Introduction to Generate
  • User Guide
    • Getting Started
      • Requesting Generate
      • User Roles and Logging In
      • Navigating Generate
    • Resources
    • Data Population Summary
      • Producing Reports
      • Reports
      • Running Reports
    • Standard Reports
      • EDFacts Reports
        • Creating Submission Files
      • SPP/APR Reports
      • Reports Library
    • Settings
      • Toggle
      • Update
      • Metadata
      • Data Migration
    • Quality Assurance
    • Support
  • Developer Guides
    • Getting Started
    • Installation
      • OAuth Configuration
      • Configuring Metadata Updates
      • Subfolder configuration
      • Optional Installations
      • Azure Installation Guide
      • Upgrade
        • Generate Update
        • Optional Installations
    • Migration
      • Fact Type Table
        • Assessment Fact Type
        • Child Count Fact Type
        • Directory Fact Type
        • Discipline Fact Type
        • Exiting Fact Type
        • Membership
        • Staff
    • Generate Utilities
      • File Comparison
        • Loading Files
        • Run the File Comparison
        • Reviewing Results
        • Researching Mismatches
      • Staging Validation
        • Staging Table Validation Process
      • Rebuild Indexes
      • Cleanup Grades Offered
      • Cleanup Debug Tables
      • Source System Reference Data Mapping Utility
        • Source System Reference Data
      • Staging Table Snapshot
      • Fact Type Table Validation Process
      • Debug Views for Staging and the Fact tables
    • Generate Architecture
    • GitHub Guide
    • Discord Guide
    • Working With Generate Code
      • Migration Stored Procedures
        • Staging.RUN_DMC
        • RDS.Get_MembershipReportData
        • Staging.Staging-to-DimPeople
        • Staging.Staging-To-DimPeople_K12Students
        • Staging.Staging-to-FactK12ProgramParticipations
        • Staging.Staging-To-FactK12SeclusionsOrRestraints
        • Staging.Staging-to-FactK12StudentCounts_ChildCount
        • Staging.Staging-to-FactK12StudentCounts_Chronic
        • Staging.Staging-to-FactK12StudentCounts_Dropout
        • Staging.Staging-to-FactK12StudentCounts_GraduationRate
        • Staging.Staging-to-FactK12StudentCounts_Homeless
        • Staging.Staging-to-FactK12StudentCounts_HSGradPSEnroll
        • Staging.Staging-to-FactK12StudentCounts_Membership
        • Staging.Staging-to-FactK12StudentCounts_MigrantEducationProgram
        • Staging.Staging-to-FactK12StudentCounts_NeglectedOrDelinquent
        • Staging.Staging-to-FactK12StudentCounts_SpecEdExit
        • Staging.Staging-to-FactK12StudentCourseSections
        • Staging.Staging-to-FactK12StudentDisciplines
        • Staging.Staging-to-FactK12StudentEnrollments
        • Staging.Staging-To-FactSpecialEducation
      • Unit Test By File Spec
        • App.DimK12Staff_TestCase
        • App.DimK12Students_TestCase
        • App.FS002_TestCase
        • App.FS005_TestCase
        • App.FS006_TestCase
        • App.FS007_TestCase
        • App.FS009_TestCase
        • App.FS032_TestCase
        • App.FS033_TestCase
        • App.FS040_TestCase
  • Release Notes
    • Introduction
    • Release Notes 12.4
    • Release Notes 12.3
    • Release Notes 12.2
    • Release Notes 12.1
    • Archive
      • Release Notes 12.0
      • Release Notes 11.4
      • Release Notes 11.3
      • Release Notes 11.2
      • Release Notes 11.1
      • Release Notes 11.0
      • Release Notes 5.3
        • Generate 5.3 Office Hour
      • Release Notes 5.2
        • Generate 5.2 Office Hour
      • Release Notes 5.1
        • Generate 5.1 Office Hour
      • Release Notes 5.0
        • Generate 5.0 Office Hour
      • Release Notes 4.1
      • Release Notes 4.0
      • Release Notes 3.8
      • Release Notes 3.7
      • Release Notes 3.6
      • Release Notes 3.5
      • Release Notes 3.4
      • Release Notes 3.3
      • Release Notes 3.2
      • Release Notes 3.1
      • Release Notes 3.0
      • Release Notes 2.4
    • Release Notes 12.3
  • Hot Fixes
    • Hot Fix - 4/13/2023
Powered by GitBook
On this page
  • Overview & Purpose
  • Business Context
  • Parameters
  • Source Tables
  • Temporary Tables
  • Potential Improvements
  • Execution Steps

Was this helpful?

Edit on GitHub
  1. Developer Guides
  2. Working With Generate Code
  3. Migration Stored Procedures

Staging.RUN_DMC

Overview & Purpose

This stored procedure retrieves and formats membership report data for educational institutions. It dynamically constructs SQL queries based on input parameters to extract data from fact tables and apply various transformations including category filtering, zero count handling, and missing data obscuration. The procedure supports multiple report types and organizational levels.

Main Functions:

  • Dynamic SQL Generation

    Constructs SQL queries at runtime based on input parameters to retrieve appropriate report data

  • Zero Count Handling

    Includes or excludes records with zero counts based on parameters and business rules

  • Missing Category Obscuration

    Replaces or removes records with missing category values based on configuration

Key Calculations:

  • Dynamic SQL Generation: Creates flexible queries that adapt to different report types and filtering requirements

    Formula: Dynamic SQL construction with parameter substitution

    Business Significance: Enables a single procedure to handle multiple report formats and data structures

    Example: Building SQL statements with different category sets and report levels

  • Zero Count Handling: Controls visibility of zero-value data points in reports

    Formula: Conditional inclusion of zero count records

    Business Significance: Ensures reports show complete data sets when required or cleaner reports when zeros are not meaningful

    Example: Using @includeZeroCounts parameter to determine if zero count records should be included

  • Missing Category Obscuration: Handles missing data in a consistent way across reports

    Formula: UPDATE @reportData SET factField = -1 WHERE CategorySetCode = X AND ReportField = 'MISSING'

    Business Significance: Ensures data quality and consistency in reporting

    Example: Setting student counts to -1 for missing category values when appropriate

Data Transformations:

  • Conversion of category codes to friendly names when requested

  • Filtering data based on report code, level, year, and category set

  • Handling of missing category values through obscuration or removal

  • Dynamic inclusion of zero count records based on parameters and business rules

  • Pagination of results using start record and number of records parameters

Expected Output:

The procedure returns two result sets: 1) A paginated set of report data with organization details, categories, and count values, and 2) A count of total records matching the criteria before pagination.

Business Context

System: Educational Data Reporting System

Necessity: Provides flexible, consistent access to educational membership data across different organizational levels and reporting requirements

Business Rules:

  • Some reports require special handling for zero counts based on report code and level

  • Missing category values may be obscured with -1 values when specified

  • Performance-related reports (c175, c178, c179) have special handling when not at SEA level

  • Reports can be filtered by organization level (SEA, LEA, school)

  • Category sets control which dimensions are included in reports

Result Usage:

The data is used to generate standardized educational reports for compliance, analysis, and decision-making

Execution Frequency:

On-demand when reports are requested

Critical Periods:

  • End of school year reporting periods

  • Federal and state reporting deadlines

Parameters

Parameter
Data Type
Purpose
Required

@reportCode

varchar(50)

Identifies the specific report to generate

True

@reportLevel

varchar(50)

Specifies the organizational level for the report

True

@reportYear

varchar(50)

Specifies the school year for the report data

True

@categorySetCode

varchar(50)

Specifies which category set to use for the report

False

@includeZeroCounts

bit

Controls whether records with zero counts are included

True

@includeFriendlyCaptions

bit

Controls whether category codes are translated to friendly names

True

@obscureMissingCategoryCounts

bit

Controls handling of records with missing category values

True

@isOnlineReport

bit

Indicates if the report is being generated for online viewing

False

@startRecord

int

Starting record number for pagination

True

@numberOfRecords

int

Number of records to return for pagination

True

Source Tables

rds.FactCustomCounts

Business Purpose: Stores custom count data for specialized reports

Columns:

Name
Data Type
Business Purpose

FactCustomCountId

Unknown

Primary key for the custom count record

ReportCode

Unknown

Identifies which report the data belongs to

app.GenerateReport_FactType

Business Purpose: Maps reports to fact types

Columns:

Name
Data Type
Business Purpose

GenerateReportId

Unknown

Links to the report definition

FactTypeId

Unknown

Links to the fact type definition

rds.DimFactTypes

Business Purpose: Stores fact type definitions

Columns:

Name
Data Type
Business Purpose

DimFactTypeId

Unknown

Primary key for fact type

FactTypeCode

Unknown

Code identifying the fact type

rds.DimSchoolYears

Business Purpose: Stores school year definitions

Columns:

Name
Data Type
Business Purpose

SchoolYear

Unknown

Identifies a specific school year

app.FactTables

Business Purpose: Stores metadata about fact tables in the system

Columns:

Name
Data Type
Business Purpose

FactTableId

Unknown

Primary key for fact table metadata

FactTableName

Unknown

Name of the physical fact table

FactFieldName

Unknown

Name of the main fact field in the table

FactReportTableName

Unknown

Name of the report table associated with the fact

FactReportTableIdName

Unknown

Name of the ID field in the report table

FactReportDtoIdName

Unknown

Name of the DTO ID field

app.GenerateReports

Business Purpose: Stores report definitions

Columns:

Name
Data Type
Business Purpose

GenerateReportId

Unknown

Primary key for report definition

ReportCode

Unknown

Code identifying the report

FactTableId

Unknown

Links to the fact table used by the report

GenerateReportTypeId

Unknown

Links to the report type

app.Dimensions

Business Purpose: Stores dimension definitions

Columns:

Name
Data Type
Business Purpose

DimensionId

Unknown

Primary key for dimension definition

DimensionFieldName

Unknown

Name of the dimension field

DimensionTableId

Unknown

Links to the dimension table

app.CategorySets

Business Purpose: Stores category set definitions

Columns:

Name
Data Type
Business Purpose

CategorySetId

Unknown

Primary key for category set

CategorySetCode

Unknown

Code identifying the category set

CategorySetName

Unknown

Name of the category set

GenerateReportId

Unknown

Links to the report definition

OrganizationLevelId

Unknown

Links to the organization level

SubmissionYear

Unknown

Year the category set applies to

TableTypeId

Unknown

Links to the table type

CategorySetSequence

Unknown

Order of the category set

Temporary Tables

@reportData

Purpose: Stores the processed report data before final output

Columns:

Name
Data Type
Purpose/Calculation

Various including StateANSICode, OrganizationName, etc.

Various

Direct assignment from source data

@ReportFieldsInFactTable

Purpose: Stores the report fields available in the fact table

Columns:

Name
Data Type
Purpose/Calculation

ReportField

nvarchar(100)

Direct assignment from app.Dimensions

@ReportFieldsInCategorySet

Purpose: Stores the report fields used in the selected category set

Columns:

Name
Data Type
Purpose/Calculation

ReportField

varchar(100)

Direct assignment from app.Dimensions

#CAT_PerformanceLevel

Purpose: Stores performance level category options for performance reports

Columns:

Name
Data Type
Purpose/Calculation

Code

varchar(50)

Direct assignment from app.CategoryOptions

#performanceData_*

Purpose: Stores performance data for each category set in performance reports

Columns:

Name
Data Type
Purpose/Calculation

Various including StateANSICode, OrganizationName, etc.

Various

Generated by RDS.Get_CountSQL

Potential Improvements

Error Handling

Description: Add explicit error handling for invalid parameters and SQL execution failures

Benefits: Improved reliability and easier troubleshooting

Priority: High

Performance

Description: Optimize dynamic SQL generation to reduce string concatenation

Benefits: Improved execution time for complex reports

Priority: Medium

Code Maintainability

Description: Refactor into smaller, more focused stored procedures

Benefits: Improved maintainability and easier debugging

Priority: Medium

Security

Description: Add parameter validation to prevent SQL injection

Benefits: Improved security and data protection

Priority: High

Documentation

Description: Add comprehensive inline documentation

Benefits: Improved maintainability and knowledge transfer

Priority: Medium

Execution Steps

Step 1: Initialize variables and determine fact/report tables

Input Data: Input parameters

Transformations: None

select @factTable = ft.FactTableName, @factField = ft.FactFieldName, @factReportTable = ft.FactReportTableName, @factReportId = ft.FactReportTableIdName, @factReportDtoId = ft.FactReportDtoIdName from app.FactTables ft inner join app.GenerateReports r on ft.FactTableId = r.FactTableId where r.ReportCode = @reportCode

Step 2: Handle custom counts if applicable

Input Data: Fact table information

Transformations: None

if @factTable = 'FactCustomCounts' begin select FactCustomCountId, ReportCode, ... from rds.FactCustomCounts where ReportCode = @reportCode and ReportLevel = @reportLevel and ReportYear = @reportYear and CategorySetCode = isnull(@categorySetCode, CategorySetCode) return end

Step 3: Identify report fields in fact table and category set

Input Data: Fact table information

Transformations: None

insert into @ReportFieldsInFactTable (ReportField) select distinct upper(d.DimensionFieldName) as ReportField from App.Dimensions d inner join App.FactTable_DimensionTables fd on d.DimensionTableId = fd.DimensionTableId inner join App.FactTables ft on fd.FactTableId = ft.FactTableId where ft.FactTableName = @factTable and upper(d.DimensionFieldName) <> 'YEAR'

Step 4: Build dynamic SQL for report data retrieval

Input Data: Report fields and parameters

Transformations: Complex SQL string building

set @sql = @sql + 'declare @reportData as table (...)'

Step 5: Handle performance reports if applicable

Input Data: Report code, level, and year

Transformations: Complex SQL string building

if(@isPerformanceSql = 1) begin ... end

Step 6: Handle zero counts if applicable

Input Data: includeZeroCounts parameter

Transformations: Complex SQL string building

if @includeZeroCounts = 1 begin ... end

Step 7: Handle missing category obscuration if applicable

Input Data: obscureMissingCategoryCounts parameter

Transformations: Complex SQL string building

if @obscureMissingCategoryCounts = 1 begin ... end

Step 8: Finalize and execute dynamic SQL

Input Data: Constructed SQL string

Transformations: None

EXECUTE sp_executesql @sql, @ParmDefinition, @reportCode = @reportCode, @reportYear = @reportYear, @reportLevel = @reportLevel, @categorySetCode = @categorySetCode, @isOnlineReport=@isOnlineReport;

PreviousMigration Stored ProceduresNextRDS.Get_MembershipReportData

Was this helpful?