using > in case statement causes syntax error

情到浓时终转凉″ 提交于 2019-12-12 06:14:46

问题


Using the below code gives me a incorrect syntax near '>' the data in the Long field looks like this:

Review Body 3,
Review body 6,
Aprentice,

I've been going around in cirlces for hours traying to sort this, is it becasue I'm using a text function (Right) in a calc.

SELECT TOP 1000 [Id]
      ,[Short]
      ,[Long]
      ,CASE ISNUMERIC(RIGHT( grade.Long , 1 )) WHEN  cast(RIGHT( shiftname.Long , 1 )as int) > 4  THEN 'Qualified' ELSE 'Unqualified' END  as Grade

  FROM [RosterPro_Live].[dbo].[lookup_PostGrade] as grade

回答1:


Syntactically, as L.V. Karlsen indicates, this question overlaps with SQL Server CASE .. WHEN .. expression and CASE Statement SQL 2012.

Your question is not sufficiently clear, but in this CASE (pun half intended), it looks like you might actually want to NEST two CASE expressions and make use of BOTH variants of the CASE syntax:

SELECT TOP 1000 [Id]
  ,[Short]
  ,grade.[Long]
  ,CASE ISNUMERIC(RIGHT( grade.Long , 1 )) 
    WHEN 1 THEN
        CASE WHEN  cast(RIGHT( shiftname.Long , 1 )as int) > 4  THEN 'Qualified' ELSE 'Unqualified Shift' END  
    WHEN 0 THEN 
        'Unqualified Grade'
    END                                                                                 as Grade
FROM [dbo].[lookup_PostGrade] as grade
-- assume join to shiftname is missing    

Note that WHEN 0 could be an ELSE.



来源:https://stackoverflow.com/questions/30618063/using-in-case-statement-causes-syntax-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!