-- LOT Materials Consumption Query
-- Retrieves material consumption records for a LOT
--
-- Parameters:
--   container_id - CONTAINERID to query (16-char hex)
--
-- Note: Uses MATERIALPARTNAME (NOT MATERIALNAME)
--       Uses QTYCONSUMED (NOT CONSUMEQTY)
--       Uses TXNDATE (NOT TXNDATETIME)

SELECT
    m.CONTAINERID,
    c.CONTAINERNAME,
    m.MATERIALPARTNAME,
    m.MATERIALLOTNAME,
    m.QTYCONSUMED,
    m.WORKCENTERNAME,
    m.SPECNAME,
    m.EQUIPMENTNAME,
    m.TXNDATE
FROM DWH.DW_MES_LOTMATERIALSHISTORY m
LEFT JOIN DWH.DW_MES_CONTAINER c
    ON c.CONTAINERID = m.CONTAINERID
WHERE m.CONTAINERID = :container_id
ORDER BY m.TXNDATE
