Skip to content

Instantly share code, notes, and snippets.

@rdeavila
Last active August 29, 2015 13:58
Show Gist options
  • Save rdeavila/9996120 to your computer and use it in GitHub Desktop.
Save rdeavila/9996120 to your computer and use it in GitHub Desktop.
SQL: Como fazer select de uma coluna ou outra, usando CASE.
SELECT
e.Nome AS nome_empresa,
(Case
WHEN c.tipo_pessoa = 'J' THEN c.Nome_Fantasia
ELSE c.Nome
END ) AS nome_ordem,
c.*
FROM
LD_Cliente c,
LD_Empresa e
WHERE
c.ID_Empresa = e.ID
AND c.Ativo = TRUE
AND c.ID_Empresa IN (
3,1,16,15
)
ORDER BY
nome_ordem ASC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment