某个字段,里面的值可能是“A”、“B”、“C”。我想查出来的不是“A”、“B”、“C”。如果字段值是“A”的话,我想得到查出来的结果是“A应用操作”;如果字段值是“B”的话,我想得到查出来的结果是“B产品错误”;如果字段值是“C”的话,我想得到查出来的结果是“C需求问题”;请问该如何做?谢谢

解决方案 »

  1.   

    select case reason when 'a' then  'A应用操作' when 'b' then 'B产品错误' when 'c' then 'C需求问题' else '' end as reason from t
      

  2.   

    declare @t table
    (
     id  int IDENTITY(1,1) PRIMARY KEY,
     reason char(5) 
    )insert @t 
    select 'a'
    union all
    select 'b'
    union all
    select 'c'
    union all
    select 'd'select case reason 
    when 'a' then  'A应用操作' 
    when 'b' then 'B产品错误' 
    when 'c' then 'C需求问题' 
    else '' end as reason 
    from @t
      

  3.   

    也可以这样写declare @t table(f1 varchar(8))
    insert @t
    select 'A' 
    union select 'B'
    union select 'C'select f1=replace(replace(replace(f1,'A','应用操作'),'B','产品错误'),'C','需求问题') from @t
      

  4.   

    select case col when 'A' then 'A应用操作' 
    when 'B' then 'B产品错误' 
    when 'C' then 'C需求问题' end AS col
    from  t
    where col = ''
      

  5.   

     回复人:SassyBoy(网页炼金术师) ( 一级(初级)) 
    挺好的方法
      

  6.   

    或者也可以建立一个 映射表
    把映射关系填入
    create table reason_map(
    reason char(1)
    reason_detail varchar(50)
    )
    ,然后用视图也可以实现,假设原表结构为:
    create table reason(
    reason_id char(1)
    others varchar(50)
    )CREATE VIEW reason_mapped 
    AS 
    select reason.others,reason_map.reason_detail
    from reason left join reason_detail
    where reason.reason_id=reason_detail.reason_id