I have a column in my TIPOCLIENT table. In it appear CPF for Individual and CNPJ for Legal Entity.
I would like the moment SELECT
to come "1" to CPF and "2" to CNPJ. How can I do this?
I have a column in my TIPOCLIENT table. In it appear CPF for Individual and CNPJ for Legal Entity.
I would like the moment SELECT
to come "1" to CPF and "2" to CNPJ. How can I do this?
Use the CASE conditional.
SELECT lista_de_campos,
CASE tipocliente
WHEN 'CPF' THEN 1
ELSE 2
END AS novo_tipo_cliente
FROM sua_tabela;
select c.cpf_cnpj,
case
when length(c.cpf_cnpj) > 11 then
2
else
1
end case
from (
select '12345655551' cpf_cnpj
from dual
union
select '01234567000115' cpf_cnpj
from dual) c
Select decode(tipo,1,cpf,2,cnpj,null) campo
From tabela
A solution with DECODE. It helped!?
It would be this:
Select decode(TIPOCLIENTE,'CPF',1,'CNPJ',2,0) TIPOCLIENTE
From tabela
In this case, the value '0' will return if the value is different from the CPF or CNPJ. Also it would give to treat for if it does not find bring the own column, but there it has to verify the type of data, therefore as it is a string must return string.