来自http://msdn.microsoft.com/en-us/library/ms181765.aspx
SELECT
CASE
WHEN MIN(value) <= 0 THEN 0
WHEN MAX(1/value) >= 100 THEN 1
END
FROM Data
您可以在 WHEN 子句中使用任何布尔表达式
case
when ([dbo].[YearsInService]([DateEngaged],getdate()) = 0) then (0)
when ([dbo].[YearsInService]([DateEngaged],getdate()) = 1) then (4)
when ([dbo].[YearsInService]([DateEngaged],getdate()) = 2) then (8)
when ([dbo].[YearsInService]([DateEngaged],getdate()) = 3) then (12)
when ([dbo].[YearsInService]([DateEngaged],getdate()) = 4) then (32)
when ([dbo].[YearsInService]([DateEngaged],getdate()) = 5) then (40)
when ([dbo].[YearsInService]([DateEngaged],getdate()) = 6) then (48)
when ([dbo].[YearsInService]([DateEngaged],getdate()) = 7) then (56)
when ([dbo].[YearsInService]([DateEngaged],getdate()) = 8) then (104)
when ([dbo].[YearsInService]([DateEngaged],getdate()) = 9) then (117)
when ([dbo].[YearsInService]([DateEngaged],getdate()) >= 10) then (150)
else (-1) end
您应该在评估之前将 [dbo].[YearsInService]([DateEngaged],getdate()) 保存在变量中。