Hello,
I am scheduling a monthly ETL on the 5th and 20th.
The begin date should always be the first day of the previous month if the ETL runs on the 5th
The End Date should always be t-1
The begin date for the ETL that runs on the 20th should always be the 1st of that month.
Example
ETL Run DateBegin DateEnd Date
3/5/2016 2/1/2016 3/4/2016
3/20/2016 3/1/2016 3/19/2016
I can not figure out how to do this...
This is the variable that I need to update
DECLARE
@AutoMonthFlag VARCHAR(1)
,@BeginDate DATETIME
,@EndDate DATETIME
SET @AutoMonthFlag = ?
SET @BeginDate = ?
SET @EndDate = ?
SELECT
CASE WHEN @AutoMonthFlag = 'Y' THEN CAST(DATEADD(MONTH,-1,DATEADD(DAY,-(DATEPART(DAY,GETDATE())-1),GETDATE())) AS DATE)
ELSE @BeginDate END AS BeginDT
,CASE WHEN @AutoMonthFlag = 'Y' THEN CAST(DATEADD(DAY,-DATEPART(DAY,GETDATE()),GETDATE()) AS DATE)
ELSE @EndDate END AS EndDT
Any help would be much appreciated!!
I am scheduling a monthly ETL on the 5th and 20th.
The begin date should always be the first day of the previous month if the ETL runs on the 5th
The End Date should always be t-1
The begin date for the ETL that runs on the 20th should always be the 1st of that month.
Example
ETL Run DateBegin DateEnd Date
3/5/2016 2/1/2016 3/4/2016
3/20/2016 3/1/2016 3/19/2016
I can not figure out how to do this...
This is the variable that I need to update
DECLARE
@AutoMonthFlag VARCHAR(1)
,@BeginDate DATETIME
,@EndDate DATETIME
SET @AutoMonthFlag = ?
SET @BeginDate = ?
SET @EndDate = ?
SELECT
CASE WHEN @AutoMonthFlag = 'Y' THEN CAST(DATEADD(MONTH,-1,DATEADD(DAY,-(DATEPART(DAY,GETDATE())-1),GETDATE())) AS DATE)
ELSE @BeginDate END AS BeginDT
,CASE WHEN @AutoMonthFlag = 'Y' THEN CAST(DATEADD(DAY,-DATEPART(DAY,GETDATE()),GETDATE()) AS DATE)
ELSE @EndDate END AS EndDT
Any help would be much appreciated!!