Installed Base Warranty Expiry SQL Query Generator
Service revenue for an equipment builder often starts with one list: which machines come out of warranty in the next quarter. This generator writes the T-SQL for it from an installed base table and a customer table.
Fill in
T-SQL query
SELECT ib.serial_no,
ib.model,
c.customer_name,
ib.ship_date,
DATEADD(MONTH, 24, ib.ship_date) AS warranty_end,
DATEDIFF(DAY, GETDATE(), DATEADD(MONTH, 24, ib.ship_date)) AS days_left
FROM dbo.installed_base AS ib
INNER JOIN dbo.customers AS c
ON c.customer_id = ib.customer_id
WHERE ib.ship_date IS NOT NULL
AND DATEADD(MONTH, 24, ib.ship_date) >= CAST(GETDATE() AS date)
AND DATEADD(MONTH, 24, ib.ship_date) <= DATEADD(DAY, 90, CAST(GETDATE() AS date))
ORDER BY warranty_end ASC;Table and column names (serial_no, model, ship_date, customer_id, customer_name) are generic placeholders. Rename them to match your ERP or service database. If warranty starts at commissioning rather than shipment, swap ship_date for the commissioning date. For extended warranties, join to the contract table and use the contract end date. Test on a read replica, not on production.
Ask your ERP for warranty leads
Optional: see how installed base and warranty questions can be answered in plain language over your own data.
Optional. The tool and every export work without this. No spam.
How to use the generator
Enter your installed base table name, the customer table, the standard warranty length and how far ahead you want to look. Copy the query into SQL Server Management Studio or your reporting tool and rename the columns to match your schema. Export the result to Excel for the aftermarket sales team.
- Rename generic columns before running
- Confirm what date starts the warranty
- Exclude machines already on a service contract
- Run against a read-only copy
What the logic does
The query adds the warranty months to the ship date with DATEADD, compares that end date against today and today plus the window, and sorts by the earliest expiry. DATEDIFF shows the days left so the sales team can prioritise. Machines with no ship date are excluded because the end date cannot be derived.
Making it useful
Add a left join to the service contract table and filter for no active contract to find true leads. Add the last service visit date to see whether the customer has an active relationship. Joining spare parts spend over the last year ranks accounts by value. The query is a starting point for a lead list, not a forecast.
Common mistakes
Using ship date when the contract says commissioning date creates wrong expiry dates by weeks or months. Per-customer warranty terms, and warranty extensions after repair, need their own columns. Time zones in GETDATE can matter for expiry at midnight, so confirm whether your reports should use UTC.
Frequently Asked Questions
Does this work on PostgreSQL or MySQL?
Not as written. DATEADD, DATEDIFF and GETDATE are T-SQL. In PostgreSQL use an interval expression such as ship_date + interval '24 months' and CURRENT_DATE. MySQL uses DATE_ADD and CURDATE.
How do I handle different warranty terms per model?
Add a warranty_months column to the model or product table and replace the placeholder with that column through a join. This is more accurate than one global value.
Why not use the ERP standard report?
If your ERP has a warranty or installed base report that meets the need, use it. This query is for cases where the data lives in a custom table or you need a specific look-ahead list.
Can I schedule it?
Yes. Wrap it in a SQL Agent job or a reporting subscription that emails the result weekly to the aftermarket team. Keep access to customer data limited to those who need it.
If your service team asks these questions weekly and waits on a report writer, we can show how a read-only natural language layer over your ERP answers them directly.
Related Tools
SAP Installed Base Equipment ABAP SELECT Generator
Fill in manufacturer, model and build year to produce an ABAP report listing equipment records from the EQUI table.
Industry TemplatesOEM Aftermarket and Service Readiness Assessment
Ten questions that show whether your installed base data, spares, contracts and field service are ready to grow aftermarket revenue.
Compliance & ContractsMachine Risk Assessment Checklist (ISO 12100)
A structured checklist for the ISO 12100 risk assessment process on a new or modified machine, with critical items flagged.
More Developer Tools tools
See all- SAP Sales Order ABAP SELECT Generator (VBAK, VBAP, VBFA)
- SAP Sales Order Create BAPI ABAP Generator (BAPI_SALESORDER_CREATEFROMDAT2)
- SAP ABAP Open Items SELECT Generator
- SAP ACDOCA SQL Query Generator
- SAP QM Inspection Lot ABAP SELECT Generator
- SAP Quality Notification Pareto SQL Query Generator
- SAP QM Usage Decision BAPI Skeleton
- ABAP Custom Exception Class Generator
- ABAP Unit Test Class Generator