Expresia CASE
Permite o logica de tipul
IF-THEN-ELSE în fraze SQL fara necesitatea de a invoca
proceduri. Forma generala este:
CASE expr WHEN expr_comp1 THEN expr1
[WHEN expr_comp2 THEN expr2
WHEN expr_compn THEN exprn
ELSE expr_alternativa]
END
Exemple:
SELECT marca, nume, colaborator,
CASE colaborator
WHEN ‘N’ THEN ‘Angajat permanent’
WHEN ‘D’ THEN ‘Colaborator’
ELSE
‘Nu este specificat!’
END
AS Tip_angajat
FROM personal
Sau
SELECT marca, nume, colaborator,
CASE
WHEN colaborator =‘N’ THEN ‘Angajat permanent’
WHEN colaborator = ‘D’ THEN ‘Colaborator’
ELSE
‘Nu este specificat!’
END
AS Tip_angajat
FROM personal