Inspection Reject Rate SQL Query Generator
Quality teams often ask for reject rate by supplier and a Pareto of failing characteristics, but the ERP standard reports are rarely exact. This generator produces three SQL queries you can adapt to your own inspection tables.
Fill in
Lot reject rate by supplier
SELECT l.vendor_id AS supplier,
COUNT(*) AS lots_inspected,
SUM(CASE WHEN l.usage_decision = 'R' THEN 1 ELSE 0 END) AS lots_rejected,
100.0 * SUM(CASE WHEN l.usage_decision = 'R' THEN 1 ELSE 0 END) / COUNT(*) AS reject_rate_pct
FROM inspection_lot l
WHERE l.inspection_date >= '2026-01-01'
AND l.inspection_date <= '2026-09-30'
GROUP BY l.vendor_id
ORDER BY reject_rate_pct DESC;Top failing characteristics
SELECT r.characteristic AS characteristic,
COUNT(*) AS failures
FROM inspection_result r
JOIN inspection_lot l ON l.lot_id = r.lot_id
WHERE r.result_status = 'F'
AND l.inspection_date >= '2026-01-01'
AND l.inspection_date <= '2026-09-30'
GROUP BY r.characteristic
ORDER BY failures DESC;Failing characteristics by supplier
SELECT l.vendor_id AS supplier,
r.characteristic AS characteristic,
COUNT(*) AS failures
FROM inspection_result r
JOIN inspection_lot l ON l.lot_id = r.lot_id
WHERE r.result_status = 'F'
AND l.inspection_date >= '2026-01-01'
AND l.inspection_date <= '2026-09-30'
GROUP BY l.vendor_id, r.characteristic
HAVING COUNT(*) >= 3
ORDER BY failures DESC;Table and column names are generic placeholders. Replace them with the real names from your ERP, for example inspection lot and result tables in SAP QM, Infor, Epicor or Oracle. Check how your ERP stores decisions and results, as many store codes that need a lookup join. Test on a read replica or reporting copy first, never against a live transactional database during peak hours. Date syntax may need adjusting for your database.
Ask your ERP about supplier quality
Optional: see how a read only assistant could answer reject rate and defect questions directly from your ERP data.
Optional. The tool and every export work without this. No spam.
How to use it
Enter your table and column names in the fields. Defaults are generic, so replace them with the names from your data dictionary. Set the date range and the codes that mean rejected and failed. The tool fills the three queries, which you can copy into your SQL client or BI tool. Start with the first query to find suppliers with high reject rates, then run the others to see which characteristics drive the rejections.
What the queries compute
The first query counts inspected lots per supplier and the share with a rejected usage decision. The second counts failing results by characteristic across the period. The third combines both and uses HAVING to hide one off failures. Reject rate is lots rejected divided by lots inspected, multiplied by 100. It counts lots, not pieces, so it does not equal parts per million defective.
- Rate = rejected lots / inspected lots x 100
- Failing characteristic counts show where to focus
- HAVING threshold removes noise, change it as needed
- Join to your vendor master for names
Common mistakes
Counting lots accepted on concession as accepted without noting it, mixing multiple inspection types in one rate, and using a date column that records lot creation instead of decision date. Also watch for duplicate result rows on re inspections, which inflate failure counts. Agree the definition of a rejected lot with quality before publishing the report.
Frequently Asked Questions
Will this work with my ERP database?
The SQL is standard and should run on most databases after you replace the names. ERP tables often use coded values or separate text tables, so you may need extra joins. Verify results against a known lot before relying on them.
Why does the query use lots rather than pieces?
Most ERP inspection records are kept per lot with a usage decision. Piece level data is not always stored. If you have piece counts, add them to calculate parts per million separately.
Can I run these against the live ERP database?
Prefer a reporting copy or read only replica. Even select queries can be expensive on large tables and vendors may restrict direct database access. Check your support agreement.
How do I add supplier names?
Join your vendor master on the supplier key and select the name column. Use a left join so suppliers without a master record still appear in the report.
If you want supplier quality questions answered in plain language from your ERP, Netray builds read only, on prem assistants that show the query behind every answer.
Related Tools
Supplier Lot Rejection Notice Template
Fill in and export a formal notice telling a supplier a lot failed incoming inspection, with defect detail, sample results and requested actions.
Quality & InspectionVisual Defect Severity Classification Reference
Starting list of common inspection defects with a suggested severity class and why, to speed up writing your own defect classification procedure.
Quality & InspectionInspection Station Audit Checklist
Audit an incoming, in process or final inspection station for gauges, calibration, environment, documentation and nonconforming material control.
Quality & InspectionGauge Resolution 10 to 1 Rule Calculator
Enter the part tolerance and your gauge resolution to see the ratio achieved and the finest resolution each rule of thumb requires.
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