It is already complicated to treat value with decimals, even more converting to STRING
and change character.
The ideal would be to use calculations, define formulas, and not a gambiarra.
Therefore, it is better to multiply and/or divide.
Example:
SELECT
(CASE WHEN comida = 'batata' THEN preco * 0.01 ELSE
(CASE WHEN comida = 'carne' THEN preco * 10 ELSE
(CASE WHEN comida = 'speculoos' THEN preco * 100 ELSE preco
END) END) END) PRECO
FROM tabela
The query will work as follows: will try the 3 conditions, and if no answer, returns the preco
normal.
Edit:
Yes, basically this, I understood the above logic for number, but what if
in case they were words, how would I do it? - Shinchila_matadora
SELECT
(CASE WHEN comida = 'batata' THEN CAST(preco as DECIMAL(10,2)) * 0.01 ELSE
(CASE WHEN comida = 'carne' THEN CAST(preco as DECIMAL(10,2)) * 10 ELSE
(CASE WHEN comida = 'speculoos' THEN CAST(preco as DECIMAL(10,2)) * 100 ELSE CAST(preco as DECIMAL(10,2))
END) END) END) PRECO
FROM tabela
but if by chance the values that need to be changed are words and not numbers?
– Geraldão de Rívia
You’re saying your field
preco
is text? That’s it?– rbz
Yes, basically this, I understood the above logic for number, but what if it were words, how would I do it?
– Geraldão de Rívia
@Shinchila_matadora added in the reply. See if it works
– rbz