Using tsql greater than sign in CASE Expression

前端 未结 6 2187
耶瑟儿~
耶瑟儿~ 2021-01-17 16:02
(case [dbo].[YearsInService]([DateEngaged],getdate())
   when (0) then (0) 
   when (1) then (4) 
   when (2) then (8)
    when (3) then (12)
     when (4) then (32)         


        
6条回答
  •  星月不相逢
    2021-01-17 16:27

    You can't, the CASE YourFunction WHEN ... is for equalities only. If you need to use "greater than", you'll need to rewrite your expression this way:

    CASE WHEN [dbo].[YearsInService]([DateEngaged],getdate()) = 0 THEN 0
    WHEN [dbo].[YearsInService]([DateEngaged],getdate()) = 1 THEN 4
    WHEN.....
    WHEN [dbo].[YearsInService]([DateEngaged],getdate()) >= 10 THEN 150 ELSE -1 END
    

提交回复
热议问题