Plant Monthly Business Review SQL Generator
A monthly operations review needs the same four or five numbers, pulled the same way each time. This generator produces plain SQL for on-time delivery, scrap by item, aged work in process and weekly completions, ready to adapt to your ERP tables.
Fill in
1. On-time delivery (shipment lines)
-- Assumes columns: plant, promise_date, ship_date, ship_qty SELECT COUNT(*) AS lines_shipped, SUM(CASE WHEN ship_date <= promise_date THEN 1 ELSE 0 END) AS lines_on_time, ROUND(100.0 * SUM(CASE WHEN ship_date <= promise_date THEN 1 ELSE 0 END) / NULLIF(COUNT(*), 0), 1) AS otd_pct FROM mfg.shipment_lines WHERE plant = 'PLANT01' AND ship_date >= '2026-09-01' AND ship_date < '2026-10-01';
2. Scrap rate by item
-- Assumes columns: plant, item, qty_completed, qty_scrapped, complete_date SELECT item, SUM(qty_completed) AS good_qty, SUM(qty_scrapped) AS scrap_qty, ROUND(100.0 * SUM(qty_scrapped) / NULLIF(SUM(qty_completed) + SUM(qty_scrapped), 0), 2) AS scrap_pct FROM mfg.production_orders WHERE plant = 'PLANT01' AND complete_date >= '2026-09-01' AND complete_date < '2026-10-01' GROUP BY item HAVING SUM(qty_scrapped) > 0 ORDER BY scrap_qty DESC;
3. Open orders past due and WIP age
-- Assumes columns: order_no, item, status, release_date, due_date, qty_ordered, qty_completed SELECT order_no, item, due_date, qty_ordered - qty_completed AS qty_open, DATEDIFF(day, release_date, '2026-10-01') AS age_days FROM mfg.production_orders WHERE plant = 'PLANT01' AND status = 'RELEASED' AND DATEDIFF(day, release_date, '2026-10-01') > 30 ORDER BY age_days DESC;
4. Completed units by week
-- DATEPART(week, ...) is SQL Server syntax. Use date_trunc('week', complete_date) in PostgreSQL.
SELECT
DATEPART(week, complete_date) AS week_no,
SUM(qty_completed) AS units_completed,
COUNT(DISTINCT order_no) AS orders_closed
FROM mfg.production_orders
WHERE plant = 'PLANT01'
AND complete_date >= '2026-09-01'
AND complete_date < '2026-10-01'
GROUP BY DATEPART(week, complete_date)
ORDER BY week_no;Table and column names are generic placeholders, not those of any specific ERP. Map them to your system (for example job and shipment tables) and check dialect functions such as DATEDIFF and DATEPART for your database. Run read-only against a reporting replica.
Ask your ERP in plain language
Optional: see how read-only natural language queries over ERP data work.
Optional. The tool and every export work without this. No spam.
How to use it
Enter your schema, the production order and shipment table names, plant code and period. Copy each query into your database tool, then rename columns to match your ERP. Start with one query, check the result against a report you trust, and only then schedule it. Use the period end as an exclusive bound so the next month starts cleanly with no overlapping day.
- Run against a read-only reporting replica where possible
- Compare the first result with your existing KPI report
- Keep period bounds as parameters, never hard-coded dates
The definitions behind the queries
On-time delivery here is share of shipment lines shipped on or before the promise date. Some customers measure against the request date or use a delivery window, so agree the definition before you compare plants. Scrap rate is scrap divided by good plus scrap quantity. Aged WIP uses days since release and a threshold you set. These are common definitions, not a standard.
Reading the output
Look at OTD as a trend, not one month. Scrap by item should be read next to quantity, because a high percentage on a tiny run matters less than a moderate percentage on a high-volume part. Aged WIP often reveals orders waiting for material or inspection. The weekly completions give a rhythm check: a big spike in the last week is a sign of end-of-month pushing.
Common mistakes
Frequent errors include counting orders instead of lines for OTD, mixing time zones in date filters, including reworked quantity twice, and comparing numbers after a change of definition. Always document the definition next to the number in the review pack.
Frequently Asked Questions
Will these queries run on my ERP unchanged?
No. The table and column names are generic. You need to map them to your ERP's actual tables and check date functions for your database. The structure and logic carry over.
Why exclusive end dates?
A less-than comparison with the first day of the next period avoids missing records timestamped late on the last day and avoids double counting when the next report starts.
Which database dialect is used?
Mostly ANSI SQL, with DATEDIFF and DATEPART in SQL Server style. The notes show the PostgreSQL alternative. Oracle users would use date arithmetic and TRUNC.
Can I use this for write operations?
These are SELECT queries only. Never run reporting queries with accounts that can modify production data.
If you would rather ask these questions in plain language against live ERP data, with the SQL shown and read-only access, Netray's ERPray does that. The queries above work on their own.
Related Tools
Manufacturing Operating Rhythm and Meeting Cadence Reference
A lookup table of the standard meeting cadence for a manufacturing plant, from the shift start huddle to the annual strategy review, with owners, inputs and outputs.
Discrete ManufacturingAutomation Candidate Process Scoring Worksheet
List manual processes, enter volume and effort, score rule clarity, data quality and risk, and get a ranked automation shortlist with annual hours at stake.
Costing & FinanceManufacturing Investment Appraisal Methods Reference
Compare payback, discounted payback, NPV, IRR, profitability index, ROI and EVA: formula, decision rule, strengths and pitfalls for equipment and expansion decisions.
More Developer Tools tools
See all- SAP Sales Order ABAP SELECT Generator (VBAK, VBAP, VBFA)
- SAP Sales Order Create BAPI ABAP Generator (BAPI_SALESORDER_CREATEFROMDAT2)
- SAP ABAP Open Items SELECT Generator
- SAP ACDOCA SQL Query Generator
- SAP QM Inspection Lot ABAP SELECT Generator
- SAP Quality Notification Pareto SQL Query Generator
- SAP QM Usage Decision BAPI Skeleton
- ABAP Custom Exception Class Generator
- ABAP Unit Test Class Generator