Skip to main content

Inventory and kit calculations

Inspect the SQL for stock counts, availability, serials and recorded kit completeness.

Written by Alex Merkin

Question numbers match their folders: folder 01 contains 01-01, 01-02 and so on. The starter dashboard uses 01-05, 01-08 and 01-02; process filter values come from 01-20. OBP identities and SQL filenames remain stable.

These English-language SQL variants preserve the source calculations and inclusion rules from the 8 November 2026 snapshot. Output aliases and display-category literals are translated into English. Replace {{schema}} with your authorized schema and run one question at a time. Dashboard and viewer filters are separate.

03-01 · Inventory records by stock and production status

Count inventory records by the combination of stock status and production status.

Inspection hint: This is a record count, not SUM(quantity). One record can represent one unit, a batch or material quantity.

SELECT stockstatus AS "Stock status",productionstatus AS "Production status",count(*) AS "Stock records" FROM {{schema}}.stock WHERE deletedat IS NULL GROUP BY 1,2 ORDER BY 3 DESC;

03-02 · Recorded available inventory by SKU and revision

Compare the availablequantity field summed by SKU and item revision.

Inspection hint: No restriction to a particular stock status and no allocation calculation for a specific work order.

SELECT sku AS "SKU",skurev AS "Workflow version",count(*) AS "Stock records",sum(availablequantity) AS "Recorded available quantity" FROM {{schema}}.stock WHERE deletedat IS NULL GROUP BY 1,2 ORDER BY 1;

03-03 · Inventory, serial and run details

Locate individual stock records by SKU and serial and inspect their recorded links.

Inspection hint: Serial alone is not guaranteed unique. Run IDs are values, not built-in report links.

SELECT sku AS "SKU",serial AS "Serial",skurev AS "Workflow version",workordernumber AS "Order",stockstatus AS "Stock status",productionstatus AS "Production status",quantity AS "Stock quantity",workflowsessionitemid AS "Run ID" FROM {{schema}}.stock WHERE deletedat IS NULL ORDER BY sku,serial;

03-04 · Inventory without a run identifier

Find stock records with workflowsessionitemid IS NULL.

Inspection hint: Does not detect a non-NULL ID pointing to a deleted run. Raw material without a run may be legitimate.

SELECT sku AS "SKU",serial AS "Serial",workordernumber AS "Order",stockstatus AS "Stock status",source AS "Source",created AS "Created date" FROM {{schema}}.stock WHERE deletedat IS NULL AND workflowsessionitemid IS NULL ORDER BY created DESC;

03-05 · Inventory records created by month

See when stock records were created.

Inspection hint: This is not inventory movement or the change in inventory quantity during the month.

SELECT date_trunc('month',created) AS "Creation month",count(*) AS "Stock records" FROM {{schema}}.stock WHERE deletedat IS NULL GROUP BY 1 ORDER BY 1;

03-06 · Inventory records by source

Count stock records by recorded source.

Inspection hint: NULL becomes local; empty text remains empty. Question 03-04 displays source without this substitution.

SELECT coalesce(source,'local') AS "Source",count(*) AS "Stock records" FROM {{schema}}.stock WHERE deletedat IS NULL GROUP BY 1 ORDER BY 2 DESC;

03-07 · Serial inventory management

Count records with isserial=true versus other records.

Inspection hint: False and NULL both enter the other group. This does not check whether the serial field itself is populated.

SELECT CASE WHEN isserial THEN 'Serial-managed' ELSE 'Other' END AS "Inventory management",count(*) AS "Stock records" FROM {{schema}}.stock WHERE deletedat IS NULL GROUP BY 1;

03-08 · Recorded kit completeness by SKU

Compare stock records marked kit complete with other records.

Inspection hint: False and NULL are grouped together. No kit-component join or shortage recalculation is performed.

SELECT sku AS "SKU",count(*) AS "Stock records",count_if(kitstatus=true) AS "Marked kit complete",count_if(kitstatus=false OR kitstatus IS NULL) AS "Not marked kit complete" FROM {{schema}}.stock WHERE deletedat IS NULL GROUP BY 1 ORDER BY 2 DESC;

03-09 · SKUs found in inventory

Find SKUs present in stock and an observed description for each.

Inspection hint: Description is selected with MAX(skudesc), not by latest update. Different records can have different descriptions.

SELECT sku AS "SKU",max(skudesc) AS "Observed description",count(*) AS "Stock records" FROM {{schema}}.stock WHERE deletedat IS NULL GROUP BY 1 ORDER BY 1;

06-04 · Recorded inventory-to-run links

Compare stock records with and without a stored run ID.

Inspection hint: A non-NULL ID is treated as linked; the source does not join to confirm that the run exists.

SELECT CASE WHEN workflowsessionitemid IS NULL THEN 'No run link' ELSE 'With run link' END AS "Production-run link",count(*) AS "Stock records" FROM {{schema}}.stock WHERE deletedat IS NULL GROUP BY 1;

Related articles

Did this answer your question?