select * from [table]
where case 
when id=2 and getdate() between startdate and enddate then 1 
when id<>1 and id<>2 then 1 else 0 end=1

解决方案 »

  1.   


    select * from [table]
    where (id<>1 and id<>2)
    or (id=2 and getdate() between startdate and enddate)
      

  2.   

    select * from [table]
    where id not in(1,2)
    or (id=2 and getdate() between startdate and enddate)
      

  3.   

    select * from [table] where id not in(1,2) or (id=2 and getdate() >= startdate and getdate()<=enddate)
      

  4.   

    上面的漏了个条件id <> 1
    且在 id = 2 AND flag = 1 时
    还有另外两个条件
    startdate >= getdate() AND
    enddate <= getdate()