Type DateFrom  DateTo  
 Out 12/09/08   12/26/08       
 Out 01/01/09   01/14/09       
 In  12/27/08   01/13/09       
 In  02/15/09   03/31/09 
1,要求当type=out的时候,查询日期在DateFrom和DateTo 之间的数据不应该显示出来
1,要求当type=In的时候,查询日期在DateFrom和DateTo 之间的数据不应该显示出来[/code]如何写这个sql

解决方案 »

  1.   

    select * 
    from tb
    where getdate not between DateFrom and DateTo这样?
      

  2.   

    select * 
    from tb
    where Type in('Out','In')
    and getdate() not between DateFrom and DateTo
      

  3.   

    select *
    from tb join type as t
    on by.type=t.type
    where t.Type='Out' or
        (datefield<DateFrom and datefield>DateTo and Type='In') 
      

  4.   


    select *
    from tb join type as t
    on tb.type=t.type
    where t.Type='Out' or
        (datefield<DateFrom and datefield>DateTo and Type='In') 
      

  5.   

    有2个时间的限制
    dep
    rtn1,要求当type=out的时候,查询日期dep在DateFrom和DateTo 之间的数据不应该显示出来
    2,要求当type=In的时候,查询日期rtn在DateFrom和DateTo 之间的数据不应该显示出来
      

  6.   

    --假设有主键id
    select * from table where id not in
    (select id from table where (type='out' and DateFrom<dep<DateTo) or (type='in' and Datefrom<rtn<DateTo))