Molding Scrap and Cycle Time SQL Query Generator
Molders often have shot, scrap and cycle data in an MES or ERP but no quick way to see which tool or press is the problem. This generator writes three generic SQL queries you can adapt to your own tables.
Fill in
Generic name, replace with your MES or ERP table
1. Scrap rate by tool and press
SELECT tool_id,
press_id,
SUM(good_parts) AS good_parts,
SUM(scrap_parts) AS scrap_parts,
CASE WHEN SUM(good_parts + scrap_parts) = 0 THEN 0
ELSE 100.0 * SUM(scrap_parts) / SUM(good_parts + scrap_parts) END AS scrap_pct
FROM mold_shot_log
WHERE shot_time >= '2026-10-01'
AND shot_time < '2026-11-01'
GROUP BY tool_id, press_id
ORDER BY scrap_pct DESC;2. Average cycle time versus standard
SELECT tool_id,
press_id,
COUNT(*) AS shots,
AVG(cycle_seconds) AS avg_cycle_seconds,
28 AS standard_cycle_seconds,
AVG(cycle_seconds) - 28 AS variance_seconds,
100.0 * (AVG(cycle_seconds) - 28) / 28 AS variance_pct
FROM mold_shot_log
WHERE shot_time >= '2026-10-01'
AND shot_time < '2026-11-01'
AND cycle_seconds > 0
GROUP BY tool_id, press_id
ORDER BY variance_pct DESC;3. Tools due for preventive maintenance by shot count
SELECT tool_id,
COUNT(*) AS total_shots,
COUNT(*) - 250000 * FLOOR(COUNT(*) / 250000) AS shots_since_last_pm,
250000 - (COUNT(*) - 250000 * FLOOR(COUNT(*) / 250000)) AS shots_to_next_pm
FROM mold_shot_log
GROUP BY tool_id
HAVING COUNT(*) - 250000 * FLOOR(COUNT(*) / 250000) >= 0.9 * 250000
ORDER BY shots_to_next_pm ASC;Table and column names are generic and will not match any specific MES or ERP out of the box. Replace them with your own and check date literal syntax and the FLOOR function for your database. The shot-count query assumes one row per shot and counts from the start of the table; for a real PM program use the shot count since the last recorded maintenance event. Run on a read-only copy or reporting database first.
Ask scrap and cycle questions in plain language
Optional: see how ERPray can answer these questions over your MES or ERP data, on-premises.
Optional. The tool and every export work without this. No spam.
How to use the generator
Enter your shot or production table name and the column names for tool, press, timestamp, cycle time, good parts and scrap parts. Set a standard cycle time, a preventive maintenance interval in shots, and a date range. The output shows three queries: scrap rate by tool and press, average cycle time against standard, and tools that have reached a share of their PM interval. Copy them into your SQL client and adjust the syntax for your database engine.
- Use a reporting copy of the database where possible
- Match column names exactly to your schema
- Test with a short date range first
What each query tells you
The scrap query ranks tool and press combinations by scrap percentage so you can see whether a problem follows the tool or the machine. The cycle query compares actual average cycle time with the standard, highlighting tools that quietly run slower than costed. The shot-count query lists tools approaching their preventive maintenance interval so maintenance can plan before wear causes flash or quality loss.
Adapting it to your ERP or MES
Most plants keep shot or production data in an MES history table, a historian, or a production reporting table inside the ERP. Names and structures differ widely, so this tool stays generic. If your system stores scrap in a separate table, join it to production by order and operation. If cycle time is not stored per shot, calculate it from timestamps. Check performance on large tables, and add an index on the timestamp and tool columns.
Common mistakes
Frequent errors include dividing by zero when no parts were counted, counting warm-up shots as cycle data, using shot counts that include rejected shots without noting it, and ignoring multi-cavity tools where parts per shot differs from shots. Decide whether your counts are shots or parts, and normalize by cavity count. Also keep time zones consistent when shifts cross midnight.
Frequently Asked Questions
Will these queries run on my MES unchanged?
No. Table and column names are generic placeholders. Replace them with your own names and check date and function syntax for your database, such as SQL Server, Oracle, PostgreSQL or MySQL.
How should I count shots for multi-cavity tools?
Decide whether you track shots or parts. If your table stores parts, divide by cavities to get shots. Mixing the two skews cycle and preventive maintenance calculations, so normalize before comparing tools.
Why compare cycle time with the standard?
Costing and quotes assume a standard cycle. If the average runs longer, margin erodes unnoticed. The comparison shows which tools run slower, so you can investigate cooling, automation or process settings.
Is the PM shot count query accurate?
It is a simple approximation based on total shots in the table. For real programs, count shots since the last recorded maintenance event stored in your maintenance system, and use this query as a starting template.
If you want to ask questions like these in plain language against your ERP or MES data, with the generated query shown, Netray can help you set up ERPray on-premises.
Related Tools
Molding Defect and Reject Log Worksheet
Log defect type, press, mold and quantity rejected, and see reject rate and scrap cost automatically.
MES & Shop FloorMolding Shift Production Report Template
A shift report for a molding department capturing output, downtime, scrap and issues for the next shift.
MES & Shop FloorMold Changeover Time Log Worksheet
Log each mold change by phase, total the minutes and see which jobs miss your changeover target.
Discrete ManufacturingInjection Molding Cooling Time Calculator
Estimate the cooling time of a molded part from wall thickness, resin thermal diffusivity, melt, mold and ejection temperatures, and see how it drives total cycle time.
MES & Shop FloorInjection Press Startup and Shutdown Checklist
A practical checklist for starting up and shutting down an injection molding press, from guards and material to first-shot and purge steps.
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
Keep exploring
Free tools
- Injection Molding Cycle Time CalculatorEstimate cooling time from wall thickness and temperatures, then total cycle time, parts per hour and output per shift.
- Injection Mold Maintenance ChecklistA practical preventive maintenance checklist for injection molds, from daily checks at the press to full overhaul and storage.
- Injection Molding Process Sheet TemplateA fill-in setup sheet that records the validated process window for a mold, press and resin, ready to print or export.
Guides
- Injection Molding Job Costing: Finding Where Quoted Margin DisappearsHow injection molders find margin leaks: compare quoted and actual cycle, scrap, resin and downtime by job and part, and fix machine rates and overhead.
- Injection Molding Production Scheduling: Matching Molds, Presses and ResinHow to schedule injection molding: match molds to presses by tonnage and shot size, plan changeovers and resin drying, and keep capacity honest with real cycle data.
- How to Quote Injection Molding Jobs FasterHow injection molders cut RFQ turnaround: standard cost build-up, cycle time and press selection rules, resin pricing, and where AI drafts quotes for review.
AI on your ERP
- Epicor Kinetic AI for Injection Molders: Resin, Tooling, Scrap and Cycle Time Questions AnsweredPrivate AI on Epicor Kinetic for injection molders: query resin lots, tooling, scrap and cycle-time variance in plain English, with the query shown.
- AI on Infor SyteLine for Plastics Injection Molders: Presses, Molds, Resin and ScrapAI on Infor SyteLine for injection molders: mold and press scheduling, resin and regrind lots, scrap and cycle variance, on-prem and read-only by default.
Manufacturing hubs
- Plastics Industry Association (PLASTICS): Molders, Processors and ERP RealitiesHow injection molders and plastics processors work in the PLASTICS ecosystem: NPE, safety standards, quoting, ERP and MES, and private AI on shop data.
- Ningbo and Yuyao, Zhejiang: Molds, Plastics and Hardware ManufacturingGuide to Ningbo and Yuyao manufacturing: mold making, injection molding and hardware, the port, typical ERP and quoting problems, and where private AI helps.