1
I’m a beginner in SQL and I’m having difficulty using the CASE WHEN
.
I have a table called CRM_PROCESSO
, in which you have a column with the option of Status
, but the answer to this status is numerical, being 1 - Aberto
, 2 - Cancelado
, 3- Encerrado
and 4 - Parcial
.
The way I created the command below, it is bringing exactly the status number.
Which command would you use, so that this number changes to the answer given above, since I have already used a CASE
?
select cp.idprocesso,
cpv.descricao,
cpv.valoratual,
cp.status,
CASE cpv.descricao
when '/*CENTRODECUSTO*/' THEN 'Local de Negócio'
When '/*NUMERONOTA*/' Then 'Número da Nota'
wHEN '/*Datasolicitao*/' THEN 'Data da Solicitação'
wHEN '/*Dataemissao*/' THEN 'Data de Emissão da NF'
wHEN '/*MOTIVOCANCELAMENTO*/' THEN 'Motivo do Cancelamento'
When '/*SOLICITANTE*/' THEN 'Solicitante'
end as descricaovariavel, 1 as QNDT
FROM CRM_PROCESSO CP,
CRM_PROCESSO_VARIAVEL CPV
WHERE
(CP.IDPROCESSO = CPV.IDPROCESSO)
AND ( CP.IDPROCEDIMENTO = 34)
AND (CP.STATUS = 0/*STATUS*/)
AND ( CPV.DESCRICAO IN ('/*CENTRODECUSTO*/','/*MOTIVOCANCELAMENTO*/','/*NUMERONOTA*/','/*datasolicitao','/*dataemissao*/','/*solicitante*/') )
Please help me out!
Renan welcome. It would not be better to create a table "TIPO_STATUS" with these values and simply make a
join
? Wouldn’t need a lot of case, and nor change the select if you need to include/exclude status values, just make the changes in the table "TIPO_STATUS"– Ricardo Pontual
I was going to answer but it seems that you are unwinding. The idea given by @Ricardopunctual to me is ideal, but if you want an alternative, use the
case
(as it does in the other column)– rLinhares
now returning to your question, I did not quite understand what you do, can explain better?
– Ricardo Pontual
@Ricardopunctual... I will try to explain in layman’s way my... I have two tables ready from the system, I cannot edit them. In a so-called "crm_process', there is a lot of information, of this information only : IDPROCESS and IDSTATUS.
– Renan Vieira
The point is that when it queries this table, the status field brings back the number, and I need a command that it changes the number to description. I was able to explain better?
– Renan Vieira