Developer ToolsFree generatorPDF, Excel, Word export

BOM Compliance Declaration Gap SQL Query Generator

Compliance teams are often asked which parts in a product still lack a valid RoHS or REACH declaration. This generator writes the query so you can fill in your own table names and get a list ready for supplier follow up.

Fill in

Table that links parent to component

Generated code
Download:

Component gap list

-- Components of ASSY-1000 with no current ROHS declaration
-- Table and column names are generic: map them to your ERP schema
SELECT b.parent_item AS parent_item,
       b.component_item AS component_item,
       i.description,
       i.supplier_code,
       d.status,
       d.declaration_date,
       CASE
         WHEN d.component_item IS NULL THEN 'MISSING'
         WHEN d.status <> 'COMPLIANT' THEN 'NOT COMPLIANT'
         ELSE 'EXPIRED'
       END AS gap_reason
FROM bom_structure b
JOIN item_master i
  ON i.item = b.component_item
LEFT JOIN item_compliance_declaration d
  ON d.component_item = b.component_item
 AND d.regulation = 'ROHS'
WHERE b.parent_item = 'ASSY-1000'
  AND (d.component_item IS NULL
       OR d.status <> 'COMPLIANT'
       OR d.declaration_date < CURRENT_DATE - 730)
ORDER BY gap_reason, b.component_item;

Summary by gap reason

SELECT gap_reason, COUNT(*) AS component_count
FROM (
  SELECT CASE
           WHEN d.component_item IS NULL THEN 'MISSING'
           WHEN d.status <> 'COMPLIANT' THEN 'NOT COMPLIANT'
           ELSE 'EXPIRED'
         END AS gap_reason
  FROM bom_structure b
  LEFT JOIN item_compliance_declaration d
    ON d.component_item = b.component_item
   AND d.regulation = 'ROHS'
  WHERE b.parent_item = 'ASSY-1000'
    AND (d.component_item IS NULL
         OR d.status <> 'COMPLIANT'
         OR d.declaration_date < CURRENT_DATE - 730)
) gaps
GROUP BY gap_reason;

Table and column names are generic placeholders, not a specific ERP schema. Date arithmetic differs by database: PostgreSQL accepts CURRENT_DATE minus an integer, SQL Server needs DATEADD(day, -730, GETDATE()), Oracle accepts SYSDATE minus a number. This query reads only the first BOM level; use a recursive CTE for multi level BOMs. Test on a copy first.

Live compliance gap report

Optional: we can discuss running a read-only compliance gap report on your ERP data.

Optional. The tool and every export work without this. No spam.

How to use the generator

Enter the name of your BOM, item and declaration tables, the column names that hold parent and component, the regulation code and how old a declaration may be before it counts as expired. The output updates immediately. Copy it into your SQL client or hand it to your ERP analyst. Most ERPs store compliance flags in user defined fields, so you may need to point the declaration table at a custom table or a view.

What the query returns

Each row is a component of the chosen assembly that has no declaration for the regulation, has a declaration marked other than compliant, or has a compliant declaration older than the age limit. The gap reason column splits the work: missing means chase the supplier, not compliant means engineering must find an alternative, expired means ask for a refreshed certificate. The second query summarises counts for a status meeting.

Going beyond one level

Compliance applies to every part in the product, not only first level components. For a full explosion, wrap the BOM join in a recursive common table expression using WITH RECURSIVE or the equivalent in your database, and add an effectivity date filter so you only look at the revision that is currently released. Remember phantom assemblies and consumables that may not appear in the BOM at all.

Common mistakes

Do not treat a missing row as compliant, and do not compare dates stored as text. Also decide what the age limit means for your policy, because some customers require a refresh every year and others accept a declaration until the part changes. Keep the output as evidence by saving each run with a date for audit.

Frequently Asked Questions

Will this work with my ERP?

The structure works with most relational databases, but table and column names are placeholders. You must map them to your schema and adjust date arithmetic. Always run on a read replica or test copy first.

How do I handle multi level BOMs?

Use a recursive common table expression to explode the BOM down to the leaf components, then join the declaration table on the exploded list. Filter by revision and effectivity so retired parts are not reported.

What age limit should I use?

There is no legal number. Many companies accept two to five years for stable parts and demand a new declaration after any design, material or supplier change. Set the value from your own compliance procedure.

Can I use it for PFAS or conflict minerals?

Yes, if your declaration table stores a regulation code for them. Pick the code from the list or edit it. The logic of missing, not compliant and expired fits any declaration based requirement.

If you want this running against live ERP data with approvals and supplier emails, Netray can help build it as a read-only report or agent.