You can use the internal function MONTH, which returns which month of the given parameter, which must be a team, date, smalldatetime, datetime, datetime2 or datetimeoffset, as stated in the function documentation. Together with the MONTH, you can also use the CASE and SUM to check if the date is a specific month, if it is you sum one more, otherwise disregard, something like this:
SELECT
PE2.PessoaNome,
SUM(CASE WHEN (MONTH(PP.PAPELETA_DATA) = 1) THEN 1 ELSE 0 END) Qtd_Jan,
SUM(CASE WHEN (MONTH(PP.PAPELETA_DATA) = 2) THEN 1 ELSE 0 END) Qtd_Fev,
SUM(CASE WHEN (MONTH(PP.PAPELETA_DATA) = 3) THEN 1 ELSE 0 END) Qtd_Mar,
FROM
PAPELETA PP
INNER JOIN PESSOASDETALHE PD ON PP.PAPELETA_PESS = PD.PessoaId
INNER JOIN PESSOAS PE ON PD.AnalistaId = PE.PessoaId
INNER JOIN PESSOAS PE2 ON PP.PAPELETA_PESS = PE2.PessoaId
GROUP BY
PE2.PessoaNome
Note: I don’t have SQL SERVER to test at the moment, but the logic is this, if you have any problems, leave a comment on the answer I fix as soon as possible.
Will this report always show a period of 3 months? Or will the interval be informed by the Customer, thus generating N columns? If you need New columns, you will need to beat the date before grouping, and then use a cursor to mount a query to be executed by sp_executesql.
– Tobias Mesquita
How is the structure of your table?
– gmsantos