0
I’m using SQL Oracle. I need to return a Select that depending on the value of the column GRUPO_ECONOMICO_ID (needs to be equal to 87) it must run a Select, otherwise it must run another select... I believe I’m close to what I need, but it triggers an error that a keyword has not been found... What I’m doing wrong??
select CASE GRUPO_ECONOMICO_ID
WHEN ((select GRUPO_ECONOMICO_ID from empresa where codigo = :TOKEN) = 87)
THEN
(SELECT emp.id
from empresa emp
where emp.grupo_economico_id = 87
union
SELECT emp.id
from empresa emp
WHERE codigo = (vou chumbar um token aqui ainda a ser criado, mas ele e diferente dos outros TOKENs aqui descritos)
ELSE
(SELECT emp.id
FROM empresa emp
WHERE emp.grupo_economico_id = (
SELECT grupo_economico_id
FROM empresa
WHERE codigo = :TOKEN
))
END as total from empresa;
where codigo = :TOKEN) = 87
thiswhere
shouldn’t bewhere GRUPO_ECONOMICO_ID = 87
?– Ricardo Pontual
I don’t think because this guy does a search in the company table for the token that was passed by the user and there may return 87... Then the conditional comes from (select GRUPO_ECONOMICO_ID from company Where code = :TOKEN)
– Rafael Pádua Del Corona
Confusing, at least for me , could give an example with data ?
– Motta
Of course the idea is that when you research a company X, the user gets information from all the companies that belong to the same economic group as this company X, right? What happens is that there is a select rule specific for when specifically the economic group is 87, so I need some kind of conditional (IF.. ELSE also serves) within sql oracle to run a select or another depending on the economic group (specifically 87).
– Rafael Pádua Del Corona