Do I need in a select to add and multiply columns with variables? Mysql

0

I need to add and multiply variables with columns and show the result with a select will look like the encoding below but because it needs strings, such as "user", and variables of the decimal type select will not work, the coding? Or if the only way to do this is to grab the select values with variables doing the operations and throwing the value into the datagridview without being by select? Visual Studio Community 2017, Mysql Free.

"SELECT *, Sum (Profit * '" variavel01' ") As Total, Sum (Quantity * '" variacomissao "')     

asked by anonymous 07.10.2018 / 02:56

1 answer

0

You can use Entity Framework to solve your problem. I do not know how your project is organized, but suppose you have a layer of bank, business (rules) and screens. By the select you wrote above you can do the following in the business layer:

public List<Caixa_Cadastrado> BuscaListaProcessamentoCaixa(string usuario)
{
   List<Caixa_Cadastrado> caixas = new List<Caixa_Cadastrado>();
   caixas = db.Caixa_Cadastrado.Where(cx => cx.user.Trim().ToUpper().Equals(usuario))
      .ToList<Caixa_Cadastrado>();

   if(caixas != null && caixas.Count > 0)
   {
        foreach(Caixa_Cadastrado cx in caixas)
        {
             //Faça aqui seus cálculos...
             cx.Lucro = cx.Lucro * VARIAVEL01;
             cx.Quantidade = cx.Quantidade * VARIACOMISSAO;
        }
   }

   return caixas;
}

Still if you want to do it in the bank, I suggest using a procedure for this, let the bank only do native calculations so it does not compromise processing resources. The advantage of doing this side of the application is that this code is portable for any type of bank, should one day switch to oracle, db2 and the like ... >     

08.10.2018 / 01:40