一数据库名tableA,有三个字段 id(auto) , name(nvarchar(10), Yexist(bit),
现在想显示,如果yexist为true,则显示为“存要”,否则显示为“不存在”(而不显示真或假)
怎么写select 语句呢?

解决方案 »

  1.   

    select id,case when name='true' then '存在' else '不存在' end 状态
    from tablea你这个是mysql是吧?大概就这样,你自己改一下吧。这是SQLServer的写法
      

  2.   

    报错还是什么?你那个bit类型不应该是true啊,而应该是0、1,至于0是true还是1是true要看你的定义,但是用case when的思路应该没错
      

  3.   

    select (case when true then N'存在' else N'不存在' end) as '是否存在' from tableA
      

  4.   

    晕,看错了,应该是这样
    select id,name,case when Yexist=0 then '存在' else '不存在' end 状态
    from tablea