SQL Date Range Filter Generator for ERP Tables
Most wrong month-end numbers in ERP reports come from the date filter, not the data. This generator writes the same filter in four dialects using a half-open range, which is the pattern that survives timestamps, time zones and leap years.
Fill in
SQL Server (T-SQL)
SELECT item, whse, qty, trans_date FROM inventory_transactions WHERE trans_date >= '2026-10-01' AND trans_date < '2026-11-01'; -- Rolling window, midnight aligned SELECT item, whse, qty, trans_date FROM inventory_transactions WHERE trans_date >= DATEADD(day, -30, CAST(GETDATE() AS date)) AND trans_date < DATEADD(day, 1, CAST(GETDATE() AS date));
Oracle
SELECT item, whse, qty, trans_date FROM inventory_transactions WHERE trans_date >= DATE '2026-10-01' AND trans_date < DATE '2026-11-01'; -- Rolling window SELECT item, whse, qty, trans_date FROM inventory_transactions WHERE trans_date >= TRUNC(SYSDATE) - 30 AND trans_date < TRUNC(SYSDATE) + 1;
PostgreSQL
SELECT item, whse, qty, trans_date FROM inventory_transactions WHERE trans_date >= DATE '2026-10-01' AND trans_date < DATE '2026-11-01'; -- Rolling window SELECT item, whse, qty, trans_date FROM inventory_transactions WHERE trans_date >= CURRENT_DATE - INTERVAL '30 days' AND trans_date < CURRENT_DATE + INTERVAL '1 day';
MySQL / MariaDB
SELECT item, whse, qty, trans_date FROM inventory_transactions WHERE trans_date >= '2026-10-01' AND trans_date < '2026-11-01'; -- Rolling window SELECT item, whse, qty, trans_date FROM inventory_transactions WHERE trans_date >= CURDATE() - INTERVAL 30 DAY AND trans_date < CURDATE() + INTERVAL 1 DAY;
Always filter the raw column, never wrap it in a function such as CONVERT or TRUNC, or the index on the date column cannot be used. Check whether your ERP stores dates as true date types, as integers (for example YYYYMMDD) or as separate year and period columns before pasting.
Get your recurring ERP reports reviewed
Send us your three slowest or most error-prone report queries and we will review the filters and indexes. Optional, no obligation.
Optional. The tool and every export work without this. No spam.
How to use the generator
Enter your table and date column, the first day you want, and the day after the last day you want. The generator fills in SQL Server, Oracle, PostgreSQL and MySQL versions, plus a rolling window variant that always ends at tomorrow's midnight. Copy the block that matches your ERP database and run it in a read-only session first. If your ERP is SyteLine, Epicor, Visual or Dynamics on SQL Server, use the T-SQL block. Oracle EBS, JD Edwards on Oracle and Fusion use the Oracle block.
- Start is inclusive, end is exclusive
- Pick the end as the first day of the next month
- Use the rolling window for dashboards, fixed dates for audits
Why half-open ranges beat BETWEEN
BETWEEN is inclusive on both ends. If a column holds date and time, BETWEEN '2026-10-01' AND '2026-10-31' stops at midnight on the 31st and silently drops every transaction posted later that day. Adding 23:59:59 only moves the problem, because fractional seconds and datetime2 precision still leave gaps. A range of >= start and < next-day-start has no gap and no overlap, so adjacent months always add up to the quarter.
Reading the result and checking it
After running the query, check the minimum and maximum of the date column in the result. The minimum should be at or after your start date and the maximum strictly before the exclusive end. Then run the same filter for the adjacent period and confirm the row counts add up to the combined range. If your ERP stores dates in local time and your server runs in UTC, shift the boundaries or the first and last hours of the month will land in the wrong period.
Common mistakes
Wrapping the column in a function to strip time, for example CONVERT(date, trans_date) = '2026-10-01', forces a scan on large transaction tables. Comparing a text column to a date works in testing and breaks when someone saves a date in a different format. Hard-coding the current year into saved reports means they quietly go stale each January. Parameterize the dates in your reporting tool instead.
- Do not use BETWEEN on datetime columns
- Do not apply functions to the indexed column
- Confirm whether the column is date, datetime or an integer
- Check the server time zone against the business time zone
Frequently Asked Questions
Why is my SQL BETWEEN missing the last day of the month?
If the column includes a time part, BETWEEN '2026-10-01' AND '2026-10-31' means midnight at the start of the 31st, so anything later that day is excluded. Use >= the first day and < the first day of the next month instead.
Is a half-open range slower than BETWEEN?
No. Both forms are simple range predicates on the raw column and use the same index seek. The half-open form is only about correctness and having no overlap between adjacent periods.
What if my ERP stores dates as integers like 20261001?
Compare against integers in the same format, for example col >= 20261001 AND col < 20261101. Convert only the constants, never the column. Some ERPs use Julian style integers, so check the column definition first.
Which block should I use for SQL Server based ERPs?
Use the first block. Infor SyteLine, Epicor, Dynamics GP and many shop floor systems run on SQL Server, so the T-SQL form with DATEADD and CAST applies. Always test in a read-only or reporting copy first.
If you keep rewriting these filters by hand for every report, we can put a governed question layer over your ERP database so analysts ask in plain language and see the exact SQL used.
Related Tools
SQL Open Purchase Orders Query Template
A configurable open PO line query with open quantity, open value and days past due, ready to adapt to any ERP schema.
Developer ToolsExcel to SQL INSERT Statement Generator
Build INSERT statements from spreadsheet rows, with an Excel formula that creates the value lists and a rollback-safe wrapper.
Developer ToolsERP Data Extract PowerShell to CSV Script Generator
Creates a scheduled-task-ready PowerShell script that runs a read-only SQL query and writes a timestamped CSV with a simple log.
Developer ToolsSQL Server, Oracle, PostgreSQL and MySQL Data Type Mapping Reference
A quick lookup of equivalent data types across four databases, with the gotchas that break ERP migrations.
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
Keep exploring
Free tools
- Aerospace NCR Trend SQL Query GeneratorBuilds a SQL query for NCR counts and Pareto ranking by supplier, part or cause code over a date range using your own table and column names.
- Gage R&R Python Script Generator (Average and Range)Fill in the file name, tolerance, and get a plain Python script that computes the average and range gage R&R.
- Infor LN SQL Query GeneratorFill in the table, company number and key range to get read-only SQL for the LN database, with the physical table name built for you.
ERP fixes and how-tos
- Business Central: "Posting Date is not within your range of allowed posting dates"Fix the Business Central error 'Posting Date is not within your range of allowed posting dates' using General Ledger Setup, User Setup, work date and deferrals.
- Infor LN Date Format: User, Language, Reports and IntegrationsHow date formats work in Infor LN: user and language settings, Web UI locale, reports, and how to handle date conversion in integrations and BODs.
- How to replace NULL in Infor SyteLine (SQL, IDO and reports)Replace NULLs in SyteLine SQL views, IDO filters and SSRS report expressions with ISNULL, COALESCE and IsNothing, with working examples and the common traps.
Guides
- Querying SyteLine Data with OData Protocol IntegrationQuery SyteLine data using OData protocol through ION API. Master $filter, $select, $expand, and $orderby operators for CloudSuite Industrial data retrieval.
- SyteLine IDO Request Object: Complete Property ReferenceComplete reference for the SyteLine IDO Request object. Properties, methods, filter syntax, and usage patterns for LoadCollection, UpdateCollection, and InvokeMethod.
- How to Set Up SSRS Reports in SyteLineComplete guide to setting up SQL Server Reporting Services (SSRS) with Infor SyteLine for web-based report delivery and interactive dashboards.