0
I’m trying to count the number of birthday clients per month in my database, but I can only make it display the months that have birthday kids, for example:
But I need him to show the months that there are no birthday girls on the count of 0, but I can’t do it.
Code I made so far
--Aniversariante por Mês (quantidade e cada mês)
go
create procedure Aniversariante_Count
as
begin
select case MONTH(C.DATANASCIMENTO)
when 1 then 'Janeiro'
when 2 then 'Fevereiro'
when 3 then 'Março'
when 4 then 'Abril'
when 5 then 'Maio'
when 6 then 'Junho'
when 7 then 'Julho'
when 8 then 'Agosto'
when 9 then 'Setembro'
when 10 then 'Outubro'
when 11 then 'Novembro'
when 12 then 'Dezembro'
end as MES, count(month(C.DATANASCIMENTO)) as Aniversariantes
from CLIENTES C
group by month(C.DATANASCIMENTO)
end
Thank you for the reply, but I tested here and gave anyway, still does not appear months without birthday
– Bea
Bea if it did not work out is because as you are creating the months using the "CASE WHEN" will not appear even with the COALENSCE, in which case the best way would be using a left Join over a base of the months.
– Gigliotti
I tried it here and it worked, thank you very much
– Bea