table1表中有多个bit类型的字段
使用select case data1 where 0 then '1' when 1 then '0' end as data1 from table1 where id = '1'
可以获取到一个bit类型字段的值,那么我想同时取出多个bit类型的字段该如何写

解决方案 »

  1.   

       建议你列出你的表结构,并提供测试数据以及基于这些测试数据的所对应正确结果。
       参考一下这个贴子的提问方式http://topic.csdn.net/u/20091130/20/8343ee6a-417c-4c2d-9415-fa46604a00cf.html
       
       1. 你的 create table xxx .. 语句
       2. 你的 insert into xxx ... 语句
       3. 结果是什么样,(并给以简单的算法描述)
       4. 你用的数据库名称和版本(经常有人在MS SQL server版问 MySQL)
       
       这样想帮你的人可以直接搭建和你相同的环境,并在给出方案前进行测试,避免文字描述理解上的误差。   
      

  2.   

    select case data1
    when 1 then '0'
    when 0 then '1'
    end
    as data1
    from table1
    where id = '1'
    union 
    select case data2
    when 1 then '0'
    when 0 then '1'
    end
    as data2
    from table1
    where id = '1'谢谢,我只是想问问取出两个以上bit类型该如何获取,使用union得到的数据是按列往下排列的
      

  3.   


    CREATE TABLE [dbo].[table1](
    [id] [int] IDENTITY(1,1) NOT NULL,
    [data1] [bit] NULL,
    [data2] [bit] NULL,
    [data3] [bit] NULL,
    [data4] [bit] NULL
    表数据
    data1 data2  data3 data4
    0      1       0    1想要同时得到这几个bit型中为0 的数据
    data1  data3
      0     0