Below I have the following code where I search in a table all the data within the specified period in the declared variables. However, a specific customer has a different month closure, in which case his month starts on the 26th, and ends on the 25th.
I'm trying to make the variables bring this period but to no avail!
In this case, the variable @periodoInicial
would have to start in 2017-07-26
and the variable @periodoFinal
in 2017-08-25
, and after this period, the variables already changed to 2017-08-26
to 2017-09-25
, it is possible do that?
Code:
declare @periodoInicial as date,
@periodoFinal as date
set @periodoInicial = cast(dateadd(mm,-1,dateadd(dd,-day(getdate())+1,getdate())) as date)
set @periodoFinal = cast(dateadd(dd,-day(getdate()),getdate()) as date)
SELECT * FROM productionEnvironmentInvoiceData
where proposalDate between @periodoInicial and @periodoFinal
NOTE: I'M WITH SQL SERVER 2008