case a when 1 then x when  2 then y else a end

解决方案 »

  1.   

    当a=1时,表达式的值为x
    当a=2时,表达式的值为y
    否则,表达式的值为a
      

  2.   

    当a为1是,将a的值代替为x当为2时,代替为y其他的时候,仍然为a的内容
      

  3.   

    if a=1 then
      结果=x
    elseif a=2 then
      结果=y
    else
      结果=a
    end if
      

  4.   

    case a when 1 then x when  2 then y else a end当所查字段a 为1时,返回结果x
    当所查字段a 为2时,返回结果y
    两者都不是,返回结果a
      

  5.   

    接着在问,没有环境,今天青年放假了,
    有两个字段
    a b 
    cc a1
    cc b2如何用case when 把等于A例等于cc的,B例等于a1,改为 CC b5结果
    CC b5
      

  6.   

    update tb
    set b=case when a='cc' and b='a1' then 'b5' else b end
    这个放where条件里更好
      

  7.   


    放在select下面那?一样通用吧,我现在没有环境,没有办法测试
      

  8.   

    update tb set a='CC',b='b5' where a='cc' and b='a1' 
      

  9.   


    declare @table table (a varchar(2),b varchar(2))
    insert into @table
    select 'cc','a1' union all
    select 'cc','b2'select a,case when a='cc' and b='a1' then 'b5' else b end as b from @table/*
    a    b
    ---- ----
    cc   b5
    cc   b2
    */