select * from 表 where  getdate() between '生效时间' and isnull('失效时间','--@@@--')----@@@--要是空的需要看到,这里就写'9999-99-99',否则'0000-00-00'

解决方案 »

  1.   


    空的话怎么处理?
    空的话值查询生效时间
    我感觉是不是要分两部分查询然后用union连接
    先把失效时间为空的查询来 然后再给外面加一个生效时间的条件
    然后把生效时间和失效时间都不为空的查询出来  再给外面加上大于等于生效时间小于等于失效时间
    然后连接 不知道对不对
      

  2.   


    select * from table
    where sysdate >= start_time
    and ((sysdate <= end_time and end_time is not null) or end_time is null)--start_time生效时间 end_time失效时间
      

  3.   

    select * from 表 where  getdate() between '生效时间' and isnull('失效时间','--@@@--')----@@@--要是空的需要看到,这里就写'9999-99-99',否则'0000-00-00'

    oracle 好像没 isnull  用decode判断吗
      

  4.   

    select * from 表 where  getdate() between '生效时间' and isnull('失效时间','--@@@--')----@@@--要是空的需要看到,这里就写'9999-99-99',否则'0000-00-00'

    oracle 好像没 isnull  用decode判断吗
      

  5.   

    你用union all 好了 还快点
      

  6.   

    select * from 表 where  getdate() between '生效时间' and isnull('失效时间','--@@@--')----@@@--要是空的需要看到,这里就写'9999-99-99',否则'0000-00-00'

    oracle 好像没 isnull  用decode判断吗
    受你启发  搞定
    AND SYSDATE >= A.EFF_DATE
    AND SYSDATE <= DECODE(A.EXP_DATE,NULL,TO_DATE('9999-01-01','YYYY-MM-DD HH24:MI:SS'),A.EXP_DATE)
      

  7.   

    想了一会儿 发现方法有很多  不过union all 写起来太长了 还是用decode解决了 
    不过说起来decode到底有多慢呢
      

  8.   

    想了一会儿 发现方法有很多  不过union all 写起来太长了 还是用decode解决了 
    不过说起来decode到底有多慢呢看数据量啦~~慢的话就再想别的办法喽!