Open A/R invoices by due date
Every open customer invoice ordered by due date, with the open amount and days until (or past) the due date.
Tool
SELECT T0.DocNum, T0.CardCode, T0.CardName, T0.DocDate, T0.DocDueDate, DATEDIFF(day, GETDATE(), T0.DocDueDate) AS DaysToDue, T0.DocTotal, T0.PaidToDate, T0.DocTotal - T0.PaidToDate AS OpenAmount FROM OINV T0 WHERE T0.DocStatus = 'O' AND T0.CANCELED = 'N' ORDER BY T0.DocDueDate, T0.DocNum
SELECT T0."DocNum", T0."CardCode", T0."CardName", T0."DocDate", T0."DocDueDate", DAYS_BETWEEN(CURRENT_TIMESTAMP, T0."DocDueDate") AS "DaysToDue", T0."DocTotal", T0."PaidToDate", T0."DocTotal" - T0."PaidToDate" AS "OpenAmount" FROM OINV T0 WHERE T0."DocStatus" = 'O' AND T0."CANCELED" = 'N' ORDER BY T0."DocDueDate", T0."DocNum"
What this query answers
The finance team plans next week's cash and wants every open customer invoice in due-date order. This returns each open, not cancelled A/R invoice with the customer, the open amount and the days to the due date. A negative number means the invoice is already overdue, so one list covers both what is coming in and what is late.
Sample output
Illustrative demo values. Your columns are the same; the numbers come from your company.
| DocNum | CardCode | CardName | DocDate | DocDueDate | DaysToDue | DocTotal | PaidToDate | OpenAmount |
|---|---|---|---|---|---|---|---|---|
| 1388 | C40000 | Blue Harbor Foods | 2026-09-01 | 2026-10-01 | -40 | 4600 | 0 | 4600 |
| 1421 | C20000 | Acme Trading | 2026-10-05 | 2026-11-04 | -6 | 5300 | 2000 | 3300 |
| 1460 | C30000 | Northwind Retail | 2026-10-20 | 2026-11-19 | 9 | 8750 | 0 | 8750 |
| 1472 | C50000 | Summit Supplies | 2026-10-28 | 2026-11-27 | 17 | 3150 | 0 | 3150 |
SQL Server vs SAP HANA
DATEDIFF(day, GETDATE(), T0.DocDueDate) becomes DAYS_BETWEEN(CURRENT_TIMESTAMP, T0."DocDueDate"). The order of the two dates stays the same, so a negative result still means the invoice is past due.
Common errors and fixes
- Totals do not match the customer balance: This reads open invoices only. Open credit memos, down payments and payments on account are not deducted; use the customer balances query for the account balance.
- Foreign-currency invoices show the wrong open amount: DocTotal and PaidToDate are in local currency. Use DocTotalFC - PaidFC for the document currency.
Need this report built into SAP Business One?
A saved query answers the question once. We do SAP Business One development: add-ons, integrations and reports, from the database to the screen. Or hire a SAP Business One developer for the whole job, fixed price per phase.
Related queries
Table reference: OINV table (A/R Invoice (header))
Three steps, no signup
Copy the right version
Use the SQL Server tab for MS SQL databases and the HANA tab for SAP B1 on HANA.
Open Query Generator
In SAP Business One go to Tools → Queries → Query Generator, paste and click Execute.
Save and share
Click Save, pick a category and give the query a name. Your team can run it from Query Manager.
Questions about this tool
How do I run the open a/r invoices by due date query in SAP Business One?
Copy the version that matches your database, open Tools → Queries → Query Generator, paste it in the SQL box and click Execute. Save it to reuse it later.
Which tables does this query use?
It reads OINV from the standard SAP Business One schema. No user-defined fields are needed.
Can this be turned into a dashboard or alert?
Yes. We turn queries into Crystal reports, Excel reports that refresh themselves, SAP B1 alerts or WhatsApp messages for managers.
Built for SAP Business One teams
Need this inside SAP Business One?
We build add-ons, reports and integrations for SAP B1 on SQL Server and HANA. Tell us what you need and get a fixed price, usually within 24 hours.
