change the output type to currency

4

I have a code that gives me two columns, Expense and Total, what I can not do is that in the output of the totals it gives me in currency format ($ 1,000.00). the code is this:

SELECT    nome_evento AS Despesa, SUM(saida_caixa) AS total
FROM      genius.caixa
LEFT JOIN genius.eventos ON eventos.id = id_despesa
WHERE     'data_caixa' BETWEEN "2016-07-29" AND "2016-08-30"
AND       'saida_caixa'!= 0
GROUP BY  id_despesa;
    
asked by anonymous 23.08.2016 / 06:49

1 answer

3

It's unclear which of the columns you want to apply formatting to, so I'll show you a generic form:

SELECT FORMAT(12332.2, 2,'pt_BR');

The result is 12.332,20 .

Reference: link

Explaining better

The first parameter is the value, the second is the number of decimal places. The third is optional, where you can define the locale.
In the example I applied the place to Brazilian Portuguese.

For your case I assume it would look like this:

FORMAT(SUM(saida_caixa), 2,'pt_BR') AS total

Suggestion

I do not know where to display the data but if it is to be displayed on an HTML page, I suggest thinking of leaving the cost of processing to the client with JavaScript. Check out this link: link

I emphasize that it is a superficial suggestion and does not mean that it is the best form and not the only one. The best way depends on each case.

    
23.08.2016 / 08:24