Inventory Subledger to GL Reconciliation SQL Generator
Month-end inventory reconciliation is a join and a subtraction, but it is slow to do by hand across hundreds of items and several accounts. This generator writes the query so you can see differences by account and drill into the item-level detail.
Fill in
Generic name. Replace with your ERP table or view.
Differences at or below this are treated as matched.
Quoted, comma separated.
Reconciliation query
-- Inventory subledger vs GL by account for period 202609
-- Table and column names are generic: map them to your ERP.
WITH sub AS (
SELECT inventory_account AS gl_account,
SUM(extended_value) AS sub_value
FROM inventory_valuation
WHERE period = '202609'
AND inventory_account IN ('1300','1310','1320')
GROUP BY inventory_account
),
gl AS (
SELECT gl_account,
SUM(ending_balance) AS gl_value
FROM gl_period_balance
WHERE period = '202609'
AND gl_account IN ('1300','1310','1320')
GROUP BY gl_account
)
SELECT COALESCE(sub.gl_account, gl.gl_account) AS gl_account,
COALESCE(sub.sub_value, 0) AS subledger_value,
COALESCE(gl.gl_value, 0) AS gl_value,
COALESCE(sub.sub_value, 0) - COALESCE(gl.gl_value, 0) AS difference,
CASE WHEN ABS(COALESCE(sub.sub_value, 0) - COALESCE(gl.gl_value, 0)) <= 1.00
THEN 'MATCHED' ELSE 'INVESTIGATE' END AS status
FROM sub
FULL OUTER JOIN gl ON gl.gl_account = sub.gl_account
ORDER BY ABS(COALESCE(sub.sub_value, 0) - COALESCE(gl.gl_value, 0)) DESC;Drill-down for unmatched accounts
-- Largest item-level values in the subledger for one account SELECT item_number, warehouse, quantity_on_hand, unit_cost, extended_value FROM inventory_valuation WHERE period = '202609' AND inventory_account = '1300' ORDER BY ABS(extended_value) DESC FETCH FIRST 50 ROWS ONLY;
Table and column names here are placeholders. Map them to your ERP's inventory valuation and GL balance tables or views. FULL OUTER JOIN and FETCH FIRST work on PostgreSQL, Oracle 12c+ and SQL Server needs TOP instead. Run against a reporting copy, and take the extract at the same cut-off as the GL close.
Automate the inventory tie-out
Optional: discuss how to run this reconciliation automatically from your ERP data.
Optional. The tool and every export work without this. No spam.
How to use the query
Replace the generic table and column names with those from your ERP's inventory valuation view and GL period balance view, then set the period, the inventory control accounts and a tolerance. Run it after the subledger is closed and the GL period is final. The first query shows each account with subledger value, GL value and a status flag, and the second query lists the largest item-level values for a drill-down.
Why the two sides differ
Frequent causes are receipts not yet matched to an invoice, manual journals posted directly to inventory accounts, production variances posted to inventory instead of variance accounts, timing differences in intercompany transfers, and standard cost revaluations posted in only one side. A difference that is identical to a single posting points to a missed or duplicated entry, while scattered small differences usually point to rounding or currency translation.
Reading the results
A MATCHED status within tolerance is expected. An INVESTIGATE status should be traced to the period transactions. Sort by absolute difference, take the largest, and walk through receipts, issues, adjustments and revaluations. Document each reconciling item with an owner and a clearing date.
Common mistakes
Comparing balances taken at different times, including non-inventory warehouses, ignoring in-transit stock accounts, and tolerances that are so large that real errors are hidden. Also remember that FULL OUTER JOIN is essential: a GL account with no subledger rows is exactly the case you need to see.
Frequently Asked Questions
How do I reconcile inventory to the general ledger?
Total the inventory subledger value by GL account at the period cut-off, compare with the GL balance of the same account, and trace differences to specific transactions such as unmatched receipts, manual journals and revaluations.
What tolerance should I use?
Use a small amount for rounding, often a few currency units per account. Larger tolerances hide real issues and should be justified in writing for auditors.
Will this run on any ERP?
The pattern is universal, but table and column names differ. You must map them. Syntax such as FETCH FIRST also varies by database, so adjust for SQL Server or MySQL.
Can I schedule it?
Yes. Run it after each period close from a reporting database, store the result with the period, and review INVESTIGATE rows. Keep a history for audit evidence.
If your reconciliation is a monthly spreadsheet exercise, we can discuss automating the extract and exception review from your ERP, read-only.
Related Tools
SAP MBEW Material Valuation ABAP SELECT Generator
Generates an ABAP SELECT on MBEW joined to MAKT that lists price control, standard price, moving average price, quantity and stock value by plant.
Costing & FinanceYear-End Inventory Audit Readiness Checklist
A 28-point checklist covering count, cutoff, valuation, reserves and documentation so inventory is ready before the external auditor arrives.
Costing & FinanceManufacturing Cost Accounting Journal Entries Reference
A lookup table of the debit and credit patterns behind a manufacturing cost flow, from raw material receipt to cost of goods sold.
Developer ToolsInventory Aging Buckets SQL Generator
Build an inventory aging query with your own table and column names and bucket sizes, ready to paste into SQL Server style SQL.
More Costing & Finance tools
See all- SAP QM Inspection Effort and Cost Calculator
- SAP Standard Cost Estimate BOM Rollup Calculator
- Legacy ERP Retirement Cost and Payback Calculator
- JD Edwards World Month-End Close Procedure Template
- Distributor Customer Credit Application Template
- Distributor Customer Profitability Worksheet
- Distributor GMROI and Inventory Turns Calculator
- Vendor Early Pay Discount Worksheet
- SyteLine Cost Rollup Variance Calculator