使用>在case语句导致语法错误 [英] using > in case statement causes syntax error

查看:255
本文介绍了使用>在case语句导致语法错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用下面的代码给我一个不正确的语法'>',Long字段中的数据如下所示:

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,

在cirlces环游小时托盘排序这是因为我正在使用一个文本功能(右)在calc。

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


推荐答案

语法上, Karlsen指出,此问题与 SQL Server CASE .. WHEN ..表达式重叠。和 CASE语句SQL 2012

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

你的问题不是很清楚,但是在这个CASE(双关意的),它看起来像你可能实际想要NEST两个CASE表达式,并使用CASE语法的BOTH变体:

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    

注意 WHEN 0 可以是 ELSE

这篇关于使用>在case语句导致语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆