LogoSupport Hub

Missing Periods Insert (Safety Check)

This script is a safety-check tool that shows you which records would be inserted into the ARCHIVES table for a specific employee if the main insertion script were run. It does not make any changes to the database.

Description

The script simulates the process of the missing_periods_insert.sql script for a single employee. It identifies all the weekly pay periods that are missing for that employee and displays them in a preview format, showing exactly what data would be inserted into each column of the ARCHIVES table.

Key functionalities include:

  • No-Change Operation: A read-only script that does not modify any data.
  • Detailed Preview: Shows the exact values that would be inserted for each missing period.
  • Employee-Specific: Requires a FILEKEY to target a single employee for analysis.
  • Confirmation Summary: Provides a total count of records that would be inserted.

How to Use

  1. Set Employee FILEKEY:
    • Open the script in your SQL editor.
    • Find the line DECLARE @FILEKEY INT = 6043;.
    • Replace 6043 with the FILEKEY of the employee you want to check.
  2. Execute the Script:
    • Run the script.
    • The output will show a preview of the records that would be created.
  3. Verify the Preview:
    • Review the records to ensure they are the ones you expect to insert. If the preview is correct, you can proceed with the actual insertion script.

Download Alternative Formats

📥 Browser Export Format:

missing_periods_insert_safety_check.sql
DECLARE @FILEKEY INT = 6043;
-- Replace with the specific employee's FILEKEY

WITH
    WeeklyPeriods
    AS
    (
        -- Generate all weekly periods from 4/20/2025 to current date
        SELECT
            DATEADD(WEEK, n, '2025-04-20') AS PERIODBEGIN,
            DATEADD(DAY, 6, DATEADD(WEEK, n, '2025-04-20')) AS PERIODEND
        FROM (
        SELECT TOP (DATEDIFF(WEEK, '2025-04-20', GETDATE()) + 1)
                ROW_NUMBER() OVER (ORDER BY (SELECT NULL)) - 1 AS n
            FROM sys.all_objects a
        CROSS JOIN sys.all_objects b
    ) Numbers
    ),
    EmployeeInfo
    AS
    (
        -- Get employee info and calculate first valid period
        SELECT
            @FILEKEY AS FILEKEY,
            e.ACTIVESTATUSEFFDATE,
            DATEADD(WEEK, -1, 
            DATEADD(DAY, -(DATEPART(WEEKDAY, e.ACTIVESTATUSEFFDATE) - 1), 
                CAST(e.ACTIVESTATUSEFFDATE AS DATE))
        ) AS FirstValidPeriodStart
        FROM EMPLOYEES e
        WHERE e.FILEKEY = @FILEKEY
            AND e.ACTIVESTATUS = 0
    ),
    MissingPeriods
    AS
    (
        -- Find missing periods for this specific employee
        SELECT
            ei.FILEKEY,
            wp.PERIODBEGIN,
            wp.PERIODEND
        FROM EmployeeInfo ei
    CROSS JOIN WeeklyPeriods wp
            LEFT JOIN ARCHIVES a ON ei.FILEKEY = a.FILEKEY
                AND wp.PERIODBEGIN = a.PERIODBEGIN
                AND wp.PERIODEND = a.PERIODEND
        WHERE a.FILEKEY IS NULL
            AND wp.PERIODBEGIN >= ei.FirstValidPeriodStart
            AND wp.PERIODBEGIN <= GETDATE()
    )
-- Show exactly what would be inserted into each column
SELECT
    'PREVIEW - Would insert for Employee: ' + CAST(@FILEKEY AS VARCHAR(10)) AS PreviewNote,
    NULL AS [UNIQUEID], -- Will be auto-generated if IDENTITY column
    FILEKEY AS [FILEKEY],
    PERIODBEGIN AS [EVENTDATE],
    PERIODBEGIN AS [PERIODBEGIN],
    PERIODEND AS [PERIODEND],
    0 AS [GROSS],
    0 AS [HOURS],
    0 AS [DOP],
    0 AS [TRANSCOUNT],
    0 AS [EXFLAGS],
    0 AS [INDIFF],
    0 AS [OUTDIFF],
    0 AS [LUN],
    0 AS [LLUN],
    0 AS [SLUN],
    0 AS [LBRK],
    0 AS [SBRK],
    '1899-12-30 00:00:00.000' AS [SCHDATE],
    '1899-12-30 00:00:00.000' AS [SCHSTART],
    '1899-12-30 00:00:00.000' AS [SCHEND],
    0 AS [SCHHOURS],
    0 AS [SCHTYPE],
    0 AS [SCHWG1],
    0 AS [SCHWG2],
    0 AS [SCHWG3],
    0 AS [SCHINDEX],
    0 AS [SCHBEN],
    0 AS [SHIFTNUM],
    0 AS [STYLE],
    0 AS [STYLE3]
FROM MissingPeriods
ORDER BY PERIODBEGIN;

-- Also show a count of how many records would be inserted
SELECT
    'Total records that would be inserted: ' + CAST(COUNT(*) AS VARCHAR(10)) AS Summary
FROM MissingPeriods;

Content Inventory

  • Doc File: content/docs/utilities/missing_periods_insert_safety_check.mdx
  • SQL Script: SQL/utilities/missing_periods_insert_safety_check.sql
  • Browser Export: public/aod/browser_exports/utilities/missing_periods_insert_safety_check.browser_export