-- Simple CASE sentence using AdventureWork Database
-- CASE simple. Evaluamos un parametro.
SELECT
d.DepartmentID,
d.Name,
d.GroupName,
CASE d.GroupName
WHEN 'Research and Development' THEN 'Cuarto A'
WHEN 'Sales and Marketing' THEN 'Cuarto B'
WHEN 'Manufacturing' THEN 'Cuarto C'
ELSE 'Cuarto D'
END AS Tipo_Cuarto
FROM HumanResources.Department AS d
DECLARE @valor INT = 0
SELECT
d.DepartmentID,
d.Name,
d.GroupName,
CASE
WHEN d.Name = 'Research and Development' AND @valor = 1 THEN 'Cuarto A'
WHEN d.Name = 'Sales' OR d.DepartmentID = 4 THEN 'Cuarto B'
WHEN d.Name LIKE 'T%' THEN 'Cuarto C'
ELSE 'Cuarto D'
END AS Tipo_Cuarto
FROM HumanResources.Department AS d
No hay comentarios:
Publicar un comentario