Imagine two companies with the same revenue. One grows calmly; the other lives in a permanent scramble, redoing deliveries and arguing with customers. The difference? The returns in SAP Business One that the second one never measured. In most industrial SMEs, returns and credit notes are the quietest margin leak: they never show up on the income statement under their own name, but they erode profitability month after month.
A return is not just an accounting document. It is the visible scar of an invisible problem: a quality defect, a shipping error, a sales promise that wasn't kept. Anyone who doesn't measure their returns is navigating with a broken compass, convinced they are making progress while the ship takes on water. In this tutorial I hand you the exact SQL queries to light up that blind spot in your ERP.

Why you need to measure returns in your company
A return costs far more than the value of the product coming back. It means reverse logistics, rework, putting stock back in, accounting adjustments and, above all, wear and tear on the customer relationship. Yet most managers only know the total invoiced amount, never the percentage that walks back in through the rear door.
When you measure returns systematically, three things happen. First, you identify which products concentrate the defects and you can attack the root cause. You also discover which customers return disproportionately, which often reveals badly managed commercial expectations. Finally, you quantify the real margin impact, turning an uncomfortable hunch into a decision based on data.
This analysis therefore stops being an accounting report and becomes a strategic tool. It is not about counting credit notes, but about reading what your operation is silently screaming at you.
Prerequisites before running the queries
Before you copy the first SELECT, make sure you meet the following. That way you will avoid misleading results and unnecessary locks:
- Query permissions: your user must have read access to the Query Generator (Query Manager). Ideally, work with a read-only user so you don't compromise the production database.
- Know your database engine: SAP Business One runs on Microsoft SQL Server or on SAP HANA. The syntax differs, which is why this tutorial provides both versions of every query.
- Understand the document flow: in SAP, a customer's goods return is recorded in the ORDN (header) and RDN1 (lines) tables, while the A/R credit memo lives in ORIN (header) and RIN1 (lines).
- Define the analysis period: always work with a bounded date range so the results are comparable and the query doesn't consume more resources than it should.
Step-by-step tutorial: from document to insight
The process for building your returns analysis follows simple but rigorous logic. Below I walk you through each stage, from the panoramic view to the actionable detail.
First, open the Query Generator from the Tools > Queries > Query Generator menu. There you paste each query, press Execute and, if you wish, save it in the Query Manager for reuse. The result is living reports that any authorised person can run without touching a line of code.
Step 1: Panoramic view of credit notes by month
Every good journey starts with a general map. This first query shows you the monthly trend of A/R credit memos, so you can spot trends and anomalous spikes before digging deeper.
SQL Server
-- Monthly trend of A/R credit memos
SELECT
DATEPART(YEAR, T0.DocDate) AS Yr,
DATEPART(MONTH, T0.DocDate) AS Mth,
COUNT(DISTINCT T0.DocEntry) AS CreditNoteCount,
SUM(T0.DocTotal) AS TotalCreditNotes
FROM ORIN T0
WHERE T0.DocDate >= '20260101'
GROUP BY DATEPART(YEAR, T0.DocDate), DATEPART(MONTH, T0.DocDate)
ORDER BY Yr, Mth;
SAP HANA
-- Monthly trend of A/R credit memos
SELECT
YEAR("T0"."DocDate") AS "Yr",
MONTH("T0"."DocDate") AS "Mth",
COUNT(DISTINCT "T0"."DocEntry") AS "CreditNoteCount",
SUM("T0"."DocTotal") AS "TotalCreditNotes"
FROM ORIN "T0"
WHERE "T0"."DocDate" >= '2026-01-01'
GROUP BY YEAR("T0"."DocDate"), MONTH("T0"."DocDate")
ORDER BY "Yr", "Mth";
For example, if you see credit notes spiking right after an aggressive discount campaign, you already have a valuable clue: perhaps you sold more than your operation could deliver with quality.
Step 2: Identify the products that get returned most
Once you know the magnitude, you have to go into the detail. This query joins the goods return tables (ORDN and RDN1) to reveal which items concentrate the returns. You will then be able to prioritise quality actions on the products that genuinely hurt.

SQL Server
-- Top 20 items most returned by customers
SELECT TOP 20
T1.ItemCode,
T1.Dscription AS Item,
SUM(T1.Quantity) AS UnitsReturned,
SUM(T1.LineTotal) AS AmountReturned,
COUNT(DISTINCT T0.DocEntry) AS ReturnCount
FROM ORDN T0
INNER JOIN RDN1 T1 ON T0.DocEntry = T1.DocEntry
WHERE T0.DocDate >= '20260101'
GROUP BY T1.ItemCode, T1.Dscription
ORDER BY UnitsReturned DESC;
SAP HANA
-- Top 20 items most returned by customers
SELECT
"T1"."ItemCode",
"T1"."Dscription" AS "Item",
SUM("T1"."Quantity") AS "UnitsReturned",
SUM("T1"."LineTotal") AS "AmountReturned",
COUNT(DISTINCT "T0"."DocEntry") AS "ReturnCount"
FROM ORDN "T0"
INNER JOIN RDN1 "T1" ON "T0"."DocEntry" = "T1"."DocEntry"
WHERE "T0"."DocDate" >= '2026-01-01'
GROUP BY "T1"."ItemCode", "T1"."Dscription"
ORDER BY "UnitsReturned" DESC
LIMIT 20;
Step 3: Calculate the return rate by customer
Here is the insight that changes boardroom conversations. Knowing how much a customer returns in absolute terms is not enough; you need to know what percentage of what you sell them comes back. That is how you tell the large customer who returns little from the mid-sized one who is eating your margin.
This query compares invoicing (OINV) against credit notes (ORIN) for each customer and calculates the return percentage. Remember to read it alongside volume, though: a 30% return rate on small sales weighs differently from 8% on your star customer.
SQL Server
-- Return rate by customer: credit notes over sales
SELECT
V.CardCode,
V.CardName,
V.Sales,
ISNULL(N.CreditNotes, 0) AS CreditNotes,
CAST(ISNULL(N.CreditNotes, 0) * 100.0
/ NULLIF(V.Sales, 0) AS DECIMAL(10,2)) AS PctReturns
FROM (
SELECT T0.CardCode, T0.CardName, SUM(T0.DocTotal) AS Sales
FROM OINV T0
WHERE T0.DocDate >= '20260101'
GROUP BY T0.CardCode, T0.CardName
) V
LEFT JOIN (
SELECT T0.CardCode, SUM(T0.DocTotal) AS CreditNotes
FROM ORIN T0
WHERE T0.DocDate >= '20260101'
GROUP BY T0.CardCode
) N ON V.CardCode = N.CardCode
ORDER BY PctReturns DESC;
SAP HANA
-- Return rate by customer: credit notes over sales
SELECT
"V"."CardCode",
"V"."CardName",
"V"."Sales",
IFNULL("N"."CreditNotes", 0) AS "CreditNotes",
CAST(IFNULL("N"."CreditNotes", 0) * 100.0
/ NULLIF("V"."Sales", 0) AS DECIMAL(10,2)) AS "PctReturns"
FROM (
SELECT "T0"."CardCode", "T0"."CardName", SUM("T0"."DocTotal") AS "Sales"
FROM OINV "T0"
WHERE "T0"."DocDate" >= '2026-01-01'
GROUP BY "T0"."CardCode", "T0"."CardName"
) "V"
LEFT JOIN (
SELECT "T0"."CardCode", SUM("T0"."DocTotal") AS "CreditNotes"
FROM ORIN "T0"
WHERE "T0"."DocDate" >= '2026-01-01'
GROUP BY "T0"."CardCode"
) "N" ON "V"."CardCode" = "N"."CardCode"
ORDER BY "PctReturns" DESC;
Advanced variations and use cases
The three queries above are your foundation. The real value, though, appears when you adapt them to the reality of your business. Below I show you the most powerful variation for a company that takes continuous improvement seriously.

Returns grouped by reason
If you created a user field to record the cause of each return (for example, U_MotivoDev in the document header), you can group returns by reason. That turns an administrative field into a quality management tool. If you don't classify reasons yet, this query is the best argument for starting.
SQL Server
-- Returns grouped by reason (user field)
SELECT
ISNULL(T0.U_MotivoDev, 'Unclassified') AS Reason,
COUNT(DISTINCT T0.DocEntry) AS ReturnCount,
SUM(T1.LineTotal) AS AmountReturned
FROM ORDN T0
INNER JOIN RDN1 T1 ON T0.DocEntry = T1.DocEntry
WHERE T0.DocDate >= '20260101'
GROUP BY ISNULL(T0.U_MotivoDev, 'Unclassified')
ORDER BY AmountReturned DESC;
SAP HANA
-- Returns grouped by reason (user field)
SELECT
IFNULL("T0"."U_MotivoDev", 'Unclassified') AS "Reason",
COUNT(DISTINCT "T0"."DocEntry") AS "ReturnCount",
SUM("T1"."LineTotal") AS "AmountReturned"
FROM ORDN "T0"
INNER JOIN RDN1 "T1" ON "T0"."DocEntry" = "T1"."DocEntry"
WHERE "T0"."DocDate" >= '2026-01-01'
GROUP BY IFNULL("T0"."U_MotivoDev", 'Unclassified')
ORDER BY "AmountReturned" DESC;
Other useful variations include segmenting by sales rep (SlpCode field), by product line, or by source warehouse. In every case the pattern is the same: add a dimension to the GROUP BY and let the data reveal where the problem concentrates.
Best practices and common mistakes
A misread query can be worse than no query at all, because it creates false confidence. Keep these recommendations in mind before taking your numbers into a management meeting.
- Don't mix returns and credit notes without criteria. A goods return (ORDN) involves physically putting stock back in; a credit note (ORIN) is a financial adjustment that may or may not involve product. A credit note for a subsequent discount, for example, is not a quality return.
- Account for taxes. The DocTotal field includes taxes. If you want to compare real margins, use net amounts or work at line level with LineTotal, which excludes VAT.
- Filter out cancelled documents. For fine-grained analysis, add a condition on the CANCELED field to exclude cancelled documents and avoid duplication.
- Always bound the period. Running a query with no date filter over years of history slows the system down and delivers results that are hard to compare.
- Automate with alerts. Once the query is validated, connect it to an alert or a Business Intelligence dashboard so the data reaches you on its own, without depending on someone running it.
Official SAP Resources
To go deeper into the table structure and data model of SAP Business One, I recommend leaning on the official documentation. The SDK table reference details every field in ORIN, RIN1, ORDN and RDN1, and it is invaluable when you build complex queries. The SAP help portal (help.sap.com) also offers version-specific guides, including the differences particular to the HANA engine.
Conclusion: turn your returns into a competitive advantage
Measuring returns in SAP Business One is not an accounting exercise, it is an act of leadership. Whoever knows what gets returned, who returns it and why stops reacting and starts anticipating. They attack the root cause, protect their margin and build healthier, more profitable commercial relationships.
The queries in this tutorial are your compass. It is up to you to decide whether you leave them filed away or turn them into a management routine that converts data into decisions. The difference between the two companies at the start was never revenue: it was what each one chose to look at.
Start today: run the first query in your test environment, identify your most returned product and take that number to your next operations meeting. If you want to master more strategic analysis on your ERP, this is the path to stop administering SAP and start leading with it.




