Overdue customer invoices
Open invoices past their due date, with days overdue and the customer phone number.
Tool
SELECT T0.DocNum, T0.CardCode, T0.CardName, T1.Phone1, T0.DocDueDate, DATEDIFF(day, T0.DocDueDate, GETDATE()) AS DaysOverdue, T0.DocTotal - T0.PaidToDate AS OpenAmount FROM OINV T0 INNER JOIN OCRD T1 ON T0.CardCode = T1.CardCode WHERE T0.DocStatus = 'O' AND T0.CANCELED = 'N' AND T0.DocDueDate < GETDATE() ORDER BY DaysOverdue DESC
SELECT T0."DocNum", T0."CardCode", T0."CardName", T1."Phone1", T0."DocDueDate", DAYS_BETWEEN(T0."DocDueDate", CURRENT_TIMESTAMP) AS "DaysOverdue", T0."DocTotal" - T0."PaidToDate" AS "OpenAmount" FROM OINV T0 INNER JOIN OCRD T1 ON T0."CardCode" = T1."CardCode" WHERE T0."DocStatus" = 'O' AND T0."CANCELED" = 'N' AND T0."DocDueDate" < CURRENT_TIMESTAMP ORDER BY "DaysOverdue" DESC
What this query answers
The collections assistant starts the day with a call list: which invoices are past due, by how many days, how much is open and which number to dial. The most overdue invoices come first.
Sample output
Illustrative demo values. Your columns are the same; the numbers come from your company.
| DocNum | CardCode | CardName | Phone1 | DocDueDate | DaysOverdue | OpenAmount |
|---|---|---|---|---|---|---|
| 3051 | C50000 | Summit Supplies | +1 555 0142 | 2026-07-16 | 100 | 3150 |
| 3124 | C40000 | Blue Harbor Foods | +1 555 0188 | 2026-08-28 | 57 | 1800 |
| 3190 | C20000 | Acme Trading | +1 555 0101 | 2026-09-24 | 30 | 5300 |
| 3233 | C30000 | Northwind Retail | 2026-10-14 | 10 | 2450 |
SQL Server vs SAP HANA
DATEDIFF(day, ..., GETDATE()) becomes DAYS_BETWEEN(..., CURRENT_TIMESTAMP), and the filter DocDueDate < GETDATE() becomes < CURRENT_TIMESTAMP. HANA can sort by the quoted alias "DaysOverdue" just like SQL Server.
Common errors and fixes
- Invoices due today show up as overdue with 0 days: GETDATE() and CURRENT_TIMESTAMP include the time, so a due date of today at 00:00 is already smaller. Compare with the date only: CAST(GETDATE() AS date) on SQL Server, CURRENT_DATE on HANA.
- Phone column is empty for some customers: Phone1 comes from the business partner master (OCRD). If your team stores numbers on the contact person, join OCPR on T0.CntctCode and use its Cellolar or Tel1 field.
Need this report built into SAP Business One?
A saved query answers the question once. We build B2B customer portals for SAP Business One: customers see their prices, stock, order status, invoices and statements, and their orders land in SAP as sales orders. 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)) · OCRD table (Business Partners)
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 overdue customer invoices 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, OCRD 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.
