Batches expiring in the next 60 days
Batch numbers with stock that expire within 60 days, per warehouse.
SELECT T0.ItemCode, T0.DistNumber AS BatchNumber, T0.ExpDate, T1.WhsCode, T1.Quantity, DATEDIFF(day, GETDATE(), T0.ExpDate) AS DaysLeft FROM OBTN T0 INNER JOIN OBTQ T1 ON T0.AbsEntry = T1.MdAbsEntry WHERE T1.Quantity > 0 AND T0.ExpDate IS NOT NULL AND T0.ExpDate <= DATEADD(day, 60, GETDATE()) ORDER BY T0.ExpDate
SELECT T0."ItemCode", T0."DistNumber" AS "BatchNumber", T0."ExpDate", T1."WhsCode", T1."Quantity", DAYS_BETWEEN(CURRENT_TIMESTAMP, T0."ExpDate") AS "DaysLeft" FROM OBTN T0 INNER JOIN OBTQ T1 ON T0."AbsEntry" = T1."MdAbsEntry" WHERE T1."Quantity" > 0 AND T0."ExpDate" IS NOT NULL AND T0."ExpDate" <= ADD_DAYS(CURRENT_TIMESTAMP, 60) ORDER BY T0."ExpDate"
More inventory queries
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 batches expiring in the next 60 days 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 OBTN, OBTQ 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.
