1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[SQL] Formatting a '$' dollar sign to an SQL Selection Statement with SUM() in it?

Discussão em 'Outras Linguagens' iniciado por Stack, Outubro 7, 2024 às 05:23.

  1. Stack

    Stack Membro Participativo

    I'm trying to format a '$' dollar sign to column "c" which is the SUM of all rows of two other columns multiplied together. I first turn it into a character as follows:

    SELECT TO_CHAR(SUM(a * b)) AS "c"
    FROM table1;


    which works fine, but when I format it by adding 'L9,999.99' formatter it gives an error:

    SELECT TO_CHAR(SUM(a * b, 'L9,999.99') AS "c"
    FROM table1;


    So I tried doing a CAST:

    SELECT TO_CHAR(CAST(SUM(a * b) AS NUMERIC(10,2)) AS "c"
    FROM table1;


    But nothing is working.

    How can I add a '$' dollar sign to a column with a SUM() function using TO_CHAR and/or CAST?

    For reference, my intended output is to turn:

    C
    10
    10.05
    11.50


    into

    C
    $10
    $10.05
    $11.50

    Continue reading...

Compartilhe esta Página