1
Exists in SQL a function equivalent to IF
(SE
) excel? I need to do a logical test which in excel I would write like this =SE(B1_UM = "UN"; D2_QUANT / B5_QE1;D2_QUANT)
.
Here is my query:
SELECT
D2_FILIAL,
// Um monte de coluna...
CASE
B1_UM
WHEN
'UN'
THEN
D2_QUANT / B5_QE1
ELSE
D2_QUANT
END AS CALC_QUANT
FROM
SD2010 SD2
// Vários joins
WHERE com várias condições
GROUP BY
D2_FILIAL,
// Várias outras colunas no group
CALC_QUANT
And what the
query
that you are currently using?– Sorack
What exactly is the condition you want to test and the outcome you are waiting for?
– Leandro Angelo
@Leandroangelo I’m wanting the query to make a calculation based on a logic test, I talked to a friend and I arrived at this result
CASE B1_UM WHEN 'UN' THEN D2_QUANT / B5_QE1 ELSE D2_QUANT END AS CALC_QUANT
apparently it should work but DB is not recognizing the alias we created is returning the errorError : 904 - ORA-00904: "CALC_QUANT": invalid identifier
– Mhac
Mhac you seem to be using Oracle right ? You can do it like this... select case name_column when name_column = 1 then 'Show what you want' when name_column = 2 then 'show .... ' Else then 'xxxxx' end as 'XYZ' ' ....
– Lucas Brogni
@Lucasbrogni oracle11g
– Mhac
Possible duplicate of You can use if Else in Mysql queries?
– Diego Rafael Souza
Look at this response from Maniero on this subject. Although the question is about a different bank, the theory explained here is the same.
– Diego Rafael Souza