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 , not a gambiarra.
Before this, then better 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 none of them meet, returns the preco
normal
.
Edit:
Yes, basically this, I understood the logic above for number, but what if
in case they were words, how would I do that? - 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