我有个表     id           typename                name        code
DIC00000031 表许可权限      0         
DIC00000032 表许可权限 √读       1         
DIC00000033 表许可权限 √增       2         
DIC00000034 表许可权限 √读_√增      3         
name(char) code(int)
保存是表格显示:√读,数据库中保存1;显示:√增,数据库中保存2;依次类推
用select查询数据是怎样爸code列的值用 convert 类型转换成name列的值 

解决方案 »

  1.   


    select id ,typename,name,code=case name when null then null
                                            when '√读' then 1
    when '√增' then 2
    when '√读_√增'then 3 end
    from tbDIC00000031 表许可权限 NULL NULL
    DIC00000032 表许可权限 √读 1
    DIC00000033 表许可权限 √增 2
    DIC00000034 表许可权限 √读_√增 2
      

  2.   


    结果:
    DIC00000031 表许可权限 NULL NULL
    DIC00000032 表许可权限 √读 1
    DIC00000033 表许可权限 √增 2
    DIC00000034 表许可权限 √读_√增 3
      

  3.   

    select 
      id,
      typename,
      name=case code 
        when 1 then '√读'
        when 2 then '√增'    
        when 3 then '√读_√增' 
        else 0
      end,
      code
    from tb
      

  4.   

    select 
      id,
      typename,
      name=case code 
        when 1 then '√读'
        when 2 then '√增'    
        when 3 then '√读_√增' 
        else null
      end,
      code
    from table