Good morning, I need to know a% change from last month's job records to job records made this month. For this I need to compare with the current day, for example.
If today was 10/15/2015 I need to count how many tasks were opened between 01/09/2015 until 9/15/2015 remembering that this needs to be done automatically, that is, the 15th day quoted in the example has to be taken date of the machine. I just came up with this:
select *
from Solicitacao
where UsuIDGrupoRespConclusao = 2655 and
DATEPART(m, SolDataFechamento) = DATEPART(m, DATEADD(m, -1, getdate()))
AND DATEPART(yyyy, SolDataFechamento) = DATEPART(yyyy, DATEADD(m, -1, getdate()))
This query returns the tasks opened last month INTEGER, as I need the variation, I have to compare from the beginning to the current day of last month.
OBS: I'm using SQL SERVER 2008