Archive data query examples

concept brazil Updated Sep 10, 2026 1 min read archive-data-query-examples.md
Raw file servicenow.com

Query examples demonstrate how to combine live and archive data for IT operations reporting, customer service case history, and HR compliance audits.

IT operations: incident volume and MTTR

Report on incident volume and MTTR (mean time to resolve) over a rolling three-year period, broken down by priority and assignment group.

SQL
SELECT    date_trunc('month', opened_at) AS month,    priority,    DV(assignment_group) AS group_name,    COUNT(*) AS incident_count,    AVG(        CASE WHEN closed_at IS NOT NULL        THEN CAST(            (CAST(closed_at AS FLOAT) - CAST(opened_at AS FLOAT)) * 1440            AS FLOAT)        END    ) AS avg_mttr_minutesFROM (    SELECT opened_at, closed_at, priority, assignment_group    FROM incident    WHERE opened_at >= date_trunc('month',        CAST(NOW() AS DATE) - INTERVAL '36 months')    UNION ALL    SELECT opened_at, closed_at, priority, assignment_group    FROM ar_incident    WHERE opened_at >= date_trunc('month',        CAST(NOW() AS DATE) - INTERVAL '36 months')) AS three_year_historyGROUP BY month, priority, DV(assignment_group)ORDER BY month DESC, priority ASC;

Customer service: full case history for an account

Return all cases for a specific account over five years, regardless of whether they are still active or have been archived.

SQL
SELECT    number,    short_description,    priority,    state,    opened_at,    closed_at,    resolved_by,    'live' AS sourceFROM sn_customerservice_caseWHERE account = 'Acme Corporation'  AND opened_at >= '2020-01-01'
UNION ALL
SELECT    number,    short_description,    priority,    state,    opened_at,    closed_at,    resolved_by,    'archive' AS sourceFROM ar_sn_customerservice_caseWHERE account = 'Acme Corporation'  AND opened_at >= '2020-01-01'
ORDER BY opened_at ASC;

HR and compliance: employee request history

Return all service requests associated with a specific employee across their full tenure. Because archive tables store resolved display values, filter directly on the display name without resolving a sys_id.

SQL
SELECT    number,    short_description,    category,    opened_at,    closed_at,    state,    requested_for,    'live' AS sourceFROM sc_requestWHERE requested_for = 'Jane Smith'   OR opened_by = 'Jane Smith'
UNION ALL
SELECT    number,    short_description,    category,    opened_at,    closed_at,    state,    requested_for,    'archive' AS sourceFROM ar_sc_requestWHERE requested_for = 'Jane Smith'   OR opened_by = 'Jane Smith'
ORDER BY opened_at ASC;
Keywords archive dataSQL queryUNION ALLincident reportingcase history
Search documentation
Search document titles and file paths on the brazil branch