表结构:ID,Text,DataType,IsError(是否为问题数据0否,1是),IShandle(处理状态1已处理,0未处理)
         1   a       1         0        0
         2    b      1         1        0
         3    c      1         1        1
         4    d      1         0        0我想查出datatype=1的时候,所有的数据,包括已处理的问题数据,不包括未处理的问题数据
结果应该是ID为1,3,4的数据被查询出来。
请问这个要怎么写呢?

解决方案 »

  1.   

    select * from tb where DataType=1 and IShandle=1
      

  2.   

    所有的数据,包括已处理的问题数据,不包括未处理的问题数据 id为4的数据为什么要被查出来,id为4 的是没有处理的
      

  3.   

    select * from tablename where datatype=1 and not(ishandle=0 and iserror=1)
      

  4.   

    我想查出datatype=1的时候,所有的数据,包括已处理的问题数据,不包括未处理的问题数据 
    结果应该是ID为1,3,4的数据被查询出来。 你不觉得自相矛盾吗?
      

  5.   

    我想查出datatype=1的时候,所有的数据,包括已处理的问题数据,不包括未处理的问题数据 
    怎么会还有1,3,4
    按照你给的数据应该只有3
      

  6.   

    可能是楼主描述的有点问题,他所说的所有已处理的问题,应该包括不是问题的那些数据
    create table #tab
    (
    id int,
    text char(1),
    DataType bit,
    IsError bit,
    IsHandle bit
    )insert #tab
    select  1 , 'a' , 1 ,  0  , 0  union all
    select  2 , 'b' , 1 ,  1  , 0  union all
    select  3 , 'c' , 1 ,  1  , 1  union all
    select  4 , 'd' , 1 ,  0  , 0 
            select id from #tab where DataType=1 and IsError=0 or(IsError=1 and IsHandle=1)id
    -----------
    1
    3
    4(3 row(s) affected)