if(substring(@guige,2,1)<3 or substring(@guige,2,1)=6) --选取编号中第二个数小于三或是等于6
begincase 
WHEN substring(@guige,10,1)=1 THEN set @a = @a+1
WHEN substring(@guige,10,1)=2 THEN set @b = @b+1
endend服务器: 消息 156,级别 15,状态 1,过程 twotype,行 76
在关键字 'case' 附近有语法错误。
服务器: 消息 156,级别 15,状态 1,过程 twotype,行 78
在关键字 'WHEN' 附近有语法错误。
服务器: 消息 156,级别 15,状态 1,过程 twotype,行 103
在关键字 'end' 附近有语法错误。加上ELSE也不行,

解决方案 »

  1.   

    case不是这么用的,里面继续用if就可以了
      

  2.   

    case是多元运算符不是跳转语句
      

  3.   

    if(substring(@guige,2,1) <3 or substring(@guige,2,1)=6) --选取编号中第二个数小于三或是等于6 
    begin IF substring(@guige,10,1)=1 
    set @a = @a+1 
    IF substring(@guige,10,1)=2 
    set @b = @b+1 
      

  4.   

    --try
    if(substring(@guige,2,1) <3 or substring(@guige,2,1)=6) --选取编号中第二个数小于三或是等于6 
    begin 
    if 
    begin
    substring(@guige,10,1)=1 else set @a = @a+1 
    end
    if 
    begin
    substring(@guige,10,1)=2 else set @b = @b+1 
    end
    end
      

  5.   


    declare @guige char(5),@a int,@b intif(substring(@guige,2,1) <3 or substring(@guige,2,1)=6) --选取编号中第二个数小于三或是等于6 
    begin 
    select 
    (case WHEN substring(@guige,10,1)=1 THEN @a+1 
    WHEN substring(@guige,10,1)=2 THEN @b+1 
    end) as tend 
      

  6.   

    你只需记住一条就可以了:case when 只能返回值或者可计算出值的表达式, 而不能返回或者控制命令或其它表达式。