-2
I have a table customedio
guy numeric
, and when the value is less than 0, I want you to bring the message "Negative value" and when it is null
, in the different case of larger and smaller than 0 bring "null value".
But running the command below is giving the error:
ERROR: invalid input syntax for type Numeric: "Negative"
I believe it’s because I’m comparing a text with a numerical field.
How to solve?
select pr.ean, upper(pr.nome) as nome, pr.unidademedida, se.quantidade, pr.customedioinicial,
(CASE
when
fpp.customedio>=0 then fpp.customedio
when
fpp.customedio<=0 then 'Negativo'
else 'Valor nulo' end) as customedio, se.quantidade * pr.customedioinicial as Total
FROM produto PR
LEFT JOIN saldoestoque SE ON(pr.id=se.idproduto)
LEFT JOIN formacaoprecoproduto FPP ON(fpp.idproduto=pr.id)
where se.quantidade is not null order by se.quantidade desc
This command didn’t work because it converted the decimals from my average cost of 2.0000 to 2. that would be a problem. I will try to summarize my command better. My field is NUMERIC it is not accepting I type a word. select (CASE

when (fpp.customedio>=0) then fpp.customedio
when (fpp.customedio<=0) then 'Negativo'
ELSE 'DIFERENTE' end) as customedio

FROM produto PR LEFT JOIN saldoestoque SE ON(pr.id=se.idproduto) LEFT JOIN formacaoprecoproduto FPP ON(fpp.idproduto=pr.id) Where se.quantidade is not null order by se.quantidade desc
– Leonan
I understood your problem so the answer was for you to convert your number to a string and then your output field would contain only string, whether the number is the alternate text. For your number to be considered to be decimal use TO_CHAR(fpp.customedio, '99999.9999') using the appropriate amount of 9’s according to the maximum content of your field.
– anonimo
Got it, man thanks a lot for the help. :-)
– Leonan