Jump to content
Fórum Script Brasil
  • 0

Group by de Valores com Variaveis


enauy

Question

Olá Pessoal, estou fazendo um select onde me traz varios resultados de calculos feitos em variaveis, por ultimo eu teria que somar os valores de acordo com as cco_contas iguais, mas não estou conseguindo, ai vai o select, se alguém puder ajudar.

 

SET @nSaldo := 0.00; 
SET @nJuros := 0.00; 
SET @nIOF  := 0.00; 
SET @nIRRF := 0.00; 
SET @nDias := 0; 
SELECT cco.cco_conta, cco.cli_nome AS cli_nome, tipopessoa( cco.cli_cpfcnpj ) AS pessoa,  
apl.apl_ndoc, apl.apl_data, apl.apl_juros, crt.aplcrt_codigo, crt.aplcrt_nome, apl.apl_tipjur, 
@nSaldo := (SaldoContratoAplicacao( apl.cco_conta, apl.apl_ndoc, '2015-09-03', 0)) AS SaldoApl, 
@nJuros := JurosAplicacao( apl.apl_data, '2015-09-03', @nSaldo, apl.apl_juros, apl.apl_tipjur ) AS VlrJuros, 
@nDias := DATEDIFF( '2015-09-03', apl.apl_data) AS nDias, 
@nIOF := ( IF( Isencao( cco.cco_conta, "I") = 1, 0, ((tabiof(@nDias)/100) * @nJuros) ))  AS VlrIOF, 
@nIRRF := ( IF( Isencao( cco.cco_conta, "R") = 1, 0, ((tabirrf(@nDias)/100) * (@nJuros-@nIOF) )) )  AS VlrIRRF, 
( @nSaldo + @nJuros - @nIOF - @nIRRF ) AS disponivel 
FROM ap_aplicacao AS apl 
LEFT JOIN view_contas AS cco ON apl.cco_conta = cco.cco_conta 
LEFT JOIN ap_carteira AS crt ON apl.aplcrt_codigo = crt.aplcrt_codigo 
WHERE apl.apl_data <= '2015-09-03' AND ( datavazia(apl.apl_liquida) OR apl.apl_liquida > '2015-09-03')

 

 

Agradeço desde já.

 

Att

Link to comment
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Forum Statistics

    • Total Topics
      152.2k
    • Total Posts
      652k
×
×
  • Create New...