Foundry Heat Traceability SQL Query Generator
When a customer reports a cracked casting, the first question is which heat it came from and what else was poured from the same heat. This generator writes the forward and backward SQL for that heat and serial genealogy using table names you set.
Fill in
Forward trace: one heat to every casting and load
-- Forward trace for heat H-24-08817
SELECT h.heat_no,
h.pour_date,
h.alloy,
c.serial_no,
c.part_no,
c.status,
l.load_no,
l.furnace_id,
l.cycle_name,
l.completed_at
FROM foundry_heat h
JOIN casting_serial c ON c.heat_no = h.heat_no
LEFT JOIN heat_treat_load l ON l.load_no = c.load_no
WHERE h.heat_no = 'H-24-08817'
ORDER BY c.serial_no;Backward trace: one casting serial to heat, chemistry and cycle
-- Backward trace for serial CS-000451239
SELECT c.serial_no,
c.part_no,
h.heat_no,
h.pour_date,
h.alloy,
k.element,
k.result_pct,
l.load_no,
l.furnace_id,
l.cycle_name
FROM casting_serial c
JOIN foundry_heat h ON h.heat_no = c.heat_no
LEFT JOIN heat_chemistry k ON k.heat_no = h.heat_no
LEFT JOIN heat_treat_load l ON l.load_no = c.load_no
WHERE c.serial_no = 'CS-000451239'
ORDER BY k.element;Heats in a date range with castings not yet released
-- Open castings by heat, pour date between 2026-09-01 and 2026-09-30
SELECT h.heat_no,
h.pour_date,
COUNT(*) AS casting_count,
SUM(CASE WHEN c.status <> 'RELEASED' THEN 1 ELSE 0 END) AS not_released
FROM foundry_heat h
JOIN casting_serial c ON c.heat_no = h.heat_no
WHERE h.pour_date BETWEEN '2026-09-01' AND '2026-09-30'
AND h.alloy = '65-45-12 ductile iron'
GROUP BY h.heat_no, h.pour_date
HAVING SUM(CASE WHEN c.status <> 'RELEASED' THEN 1 ELSE 0 END) > 0
ORDER BY h.pour_date;Table and column names are generic placeholders, not those of any specific ERP. Map them to your own schema (for example lot, serial and work order tables) before running, run read-only on a reporting copy, and verify date and null handling for your database engine.
Read-only trace report on your ERP data
Optional: we can map these generic queries to your real tables and set up a read-only report.
Optional. The tool and every export work without this. No spam.
How to use it
Fill in the names of your heat master, chemistry, casting serial and heat treat load tables, then enter a heat number, a serial number and a date range. The tool produces three queries: a forward trace from heat to castings and loads, a backward trace from serial to heat, chemistry and load, and a list of heats with castings still unreleased. Copy the code into your reporting tool or SQL client, adjust column names to match your schema, and run it read-only on a reporting copy.
- Forward trace answers: what else came from this heat
- Backward trace answers: what is this casting made of
- The third query supports release and hold decisions
How the genealogy is modeled
Foundry traceability is a chain: melt heat, pour or mold, casting serial or lot, then downstream operations such as heat treatment, machining and test. The queries assume each casting row stores the heat number and the load number, which is the minimum link needed. If your ERP stores genealogy in a lot or serial history table, replace the direct joins with joins to that table. Left joins keep castings in the result even when chemistry or load data is missing, which is itself a useful gap finding.
- Heat number links chemistry to castings
- Load number links castings to furnace cycles
- Left joins expose missing records
Common mistakes
The most common mistake is joining on a part number rather than a heat or serial, which multiplies rows and hides the real lineage. Another is forgetting that one heat can span several pours, and one pour several heats in a ladle transfer, so confirm your model. Third, string dates and numeric results often sit in text columns, so cast them before filtering. Always test with a known heat where you can verify the casting list by hand before trusting the output in a recall or customer response.
- Join on heat or serial, not part number
- Check how ladle transfers are recorded
- Cast text dates and results before comparing
Frequently Asked Questions
Will these queries run in my ERP unchanged?
No. Table and column names are generic placeholders. Replace them with the real names in your schema, such as your lot, serial and work order tables, and check date handling for your database engine before running.
What is the difference between forward and backward trace?
A backward trace starts from a finished casting and finds its heat, chemistry and process records. A forward trace starts from a heat or lot and finds every casting and shipment made from it. Recalls need both.
Is it safe to run these on production?
They are read-only SELECT statements, but large joins can load a busy system. Run them on a reporting copy or in off-peak hours, and add date limits or indexes if the heat table is large.
Why do I need heat chemistry in the trace?
Chemistry certifies that the heat met the alloy specification, and a deviation, for example high sulfur or low magnesium in ductile iron, can explain a failure. Linking it to the serial gives you evidence at the touch of a query.
If heat, chemistry and heat treat data sit in different systems, we can help build a read-only trace report on top of your ERP. This generator is free and runs in your browser.
Related Tools
Cast Iron and Steel Casting Grades ASTM Reference
Look up ASTM A48, A536, A27, A216, A351, A148 and A897 casting grades with minimum tensile and yield values in ksi and MPa.
Discrete ManufacturingCasting Riser Sizing Modulus Calculator
Calculate riser diameter, height and volume from casting volume and cooling area, and check the riser has enough feed metal.
Quality & InspectionHeat Treat Pyrometry AMS2750 Readiness Checklist
Self-check of furnace classification, instrumentation, system accuracy tests, temperature uniformity surveys and records before a customer or Nadcap audit.
Industry TemplatesFoundry and Forge Process Control Maturity Assessment
Score how well your melt, pour, forging, heat treat, traceability and data practices are controlled, and get practical next 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