Function to return total sales

0

I have this function that returns me the amount of sales of a cnpj month to month in the year 2018, I would like it possible for someone to help me implement a variable in this function, to get the total for cnpj in the year and show how a column in a select.

ALTER FUNCTION totalDeTransmissoesNoMes(  
    @cnpjDaRevenda VARCHAR(15),  
    @ano int,  
    @mes int  
)RETURNS int AS BEGIN DECLARE @totalDeTransmissoes int;  

SET @totalDeTransmissoes = (  
    SELECT COUNT(*)  FROM enviovendas as ei  
    WHERE ei.ds_cnpjrev = @cnpjDaRevenda   
    AND YEAR(ei.dt_envio) = @ano  
    AND MONTH(ei.dt_envio) = @mes  
);   
RETURN @totalDeTransmissoes;  
END;
    
asked by anonymous 08.10.2018 / 17:50

0 answers