Em 03/12/14, Paulo Afonso Pereira<[email protected]> escreveu:
> OLÁ PESSOAL,
>
>
>
> PRECISO COLOCAR SINAIS NOS MEUS SALDOS E PRECISO DE UMA DICA.
>
> EXECUTANDO A SENTENÇA ABAIXO:
>
>     SELECT pl.classificacao
>
>                  , pl.descricao
>
>                  , coalesce(
>
>                  (
>
>                    SELECT sum (lcx.valor)
>
>                     FROM consolidado lcx
>
>                      WHERE lcx.datalan < '2014-01-01'
>
>          ),0)  AS saldo_anterior;
>
>
>
> RETORNO:
>
> ----------------
>
> -48071.06
>
> -25620.64
>
> -10000.00
>
> -31.15
>
> -1200.00
>
> -25000.00
>
> 1200.00
>
> 25000.00
>
> -20000.00
>
> -20080.00
>
> 20000.00
>
>
>
> PRECISO COLOCAR SINAIS DE 'D' PARA NEGATIVOS E 'C' PARA POSITIVOS.
>
> ESTOU TENTANDO ALGO ASSIM:
>
> -------------------------
>
> 48071.06D
>
> 25620.64D
>
> 10000.00D
>
> 31.15D
>
> 1200.00D
>
> 25000.00D
>
> 1200.00C
>
> 25000.00C
>
> 20000.00D
>
> 20080.00D
>
> 20000.00C
>
>
>
> ESTOU TENTADO ALGO DO TIPO:
>
> ---------------------------------------
>
>     SELECT pl. classificacao
>
>                  , pl.descricao
>
>                  , coalesce(
>
>                  (
>
>                    SELECT
>
>                     CASE WHEN sum (lcx.valor) < 0 THEN ABS(sum
> (lcx.valor))||'D'
>
>                                WHEN sum (lcx.valor) > 0 THEN ABS(sum
> (lcx.valor))||'C'
>
>                               ELSE '*'
>
>                    END
>
>                     FROM consolidado lcx
>
>                      WHERE lcx.datalan < '2014-01-01'
>
>          ),0)  AS saldo_inicial
>
>
>
> RETORNA O ERRO:
>
> -------------------------------
>
> ERRO:  tipos no COALESCE text e integer não podem corresponder
>
> LINE 22:        ),0)  AS saldo_inicial
>


Tente formatar o valor com sinal ao final.
to_char(campo, '999999999.99SG')
e depois troque o +/- por C/D:
translate(to_char(campo, '999999999.99SG'), '+-', 'CD')

Osvaldo
_______________________________________________
pgbr-geral mailing list
[email protected]
https://listas.postgresql.org.br/cgi-bin/mailman/listinfo/pgbr-geral

Responder a