select 1 where case right('2006-4',1) when '4' then  right('200611',2) >= '10' and  right('200611',2) <= '12' end报错
服务器: 消息 170,级别 15,状态 1,行 1
第 1 行: '>' 附近有语法错误。
应该显示是1才对的,怎么改?

解决方案 »

  1.   

    then  right('200611',2) >= '10' and  right('200611',2) <= '12'这里有错,不能用and
      

  2.   

    没看懂楼主什么意思
    既然select了,那没有from,又何来where呢?
      

  3.   

    CASE不对,楼主要什么结果?
      

  4.   

    select case right('2006-4',1) 
    when '4' then  right('200611',2) end 结果
    结果   
    ---- 
    11(所影响的行数为 1 行)
      

  5.   

    我的意思是
    本来是这样的:select 1 where left(right('200611a',3),2) >= '10' and left(right('200611a',3),2) <= '12'
    结果为1我加了CASE语句后,就报错。
    select 1 where case right('2006-4',1) when '4' then  right('200611',2) >= '10' and  right('200611',2) <= '12' end这个CASE怎么写??
      

  6.   

    忙中出错
    本来是这样的:select 1 where  right('200611',2) >= '10' and right('200611',2) <= '12'
    结果为1我加了CASE语句后,就报错。
    select 1 where case right('2006-4',1) when '4' then  right('200611',2) >= '10' and  right('200611',2) <= '12' end这个CASE怎么写??
      

  7.   

    select  case right('2006-4',1) when '4' then
     right('200611',2) >= '10' and  right('200611',2) <= '12' end返回:
    1
      

  8.   

    select (case when left(right('200611a',3),2) >= '10' and left(right('200611a',3),2) <= '12' then 1 else 0 end) a
      

  9.   

    select  case right('2006-4',1) when '4' then
     right('200611',2) >= '10' and  right('200611',2) <= '12' end
    去掉:1 where 就可以了
    返回结果:
    1
      

  10.   

    我要放在where 后面,不行么?是不是WHERE 后面不能带CASE语句??
      

  11.   

    akuzou(喝前摇一摇)虽然可以,但不是我想要 的200611是变量,要在WHERE条件下过滤的
      

  12.   

    是字段吧? 把字段放进去就可以了,语句后面带上from table
      

  13.   

    http://www.51iter.com/program/database/sql/200604/program_30970.html
      

  14.   

    select 1 where case right('2006-4',1) when '4' then  right('200611',2) >= '10' and  right('200611',2) <= '12' end 
    楼主把语法搞错case when right('2006-4',1)=4 and right('200611',2) >= '10' and right('200611',2) <= '12' and  right('200611',2) <= '12'  then 答案 end
      

  15.   

    楼主的 (left(right('200611a',3),2) >= '10' and left(right('200611a',3),2) <= '12') 
    是条件嘛,怎么写在了then 的后面??
      

  16.   

    难道就是传说中火星上SQL查询的格式?
      

  17.   

    end的位置不对。改为:
    select 1 
    where 
    case right('2006-4',1) when '4' then  right('200611',2) end >= '10' 
    and right('200611',2) <= '12'
      

  18.   


    是不是這個?
    select  case  when right('2006-4',1)='4'  
               and   right('200611',2) >= '10' and  right('200611',2) <= '12'
              then 1 end
      

  19.   

    是不是lz的字段类型不对,用cast转换一下再用<= >=试试