Function to return total sales

Asked

Viewed 52 times

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 if possible someone would help me implement a variable in this function, which takes the total per cnpj in the year and show as 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;
  • You want to do another function or in that same?

  • Hello Marconi all right? I did another function but I need to try to do in the same function.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.