Given the following fairly standard Orders table:
CREATE TABLE [dbo].[orders](
[bill_product_id] [int] IDENTITY(1,1) NOT NULL,
[Bill_date] [datetime] NULL,
[TenantId] [int] NULL,
[Product_type] [int] NULL,
[Quantity] [int] NULL,
[Customer_cost] [numeric](18, 10)
)
The following query gives me the start_date and end_date of each Month for which there are records in the table orders
SELECT distinct DATEADD(DAY,1,EOMONTH(bill_date,-1)) as start_date,
EOMONTH(bill_date) as end_date
FROM orders
Example resultset:
start_date end_date
2020-07-01 2020-07-31
2020-08-01 2020-08-31
Now we need to change the 'Billing Cycle' so instead of starting on the 1st of the month, and ending on the last day of the month, we need the start of the billing cycle to be the 26th of the month, with the end being the following 25th day of the month (don't ask).
I'm sure I can determine the end_date given the start date, but I'm unsure the best way to partition the data into 26th-to-25th of the month segments. Please suggest an effecient way to do this.