我是一个培训表,字段名中包含两个,就是培训'开始时间','结束时间'.
我的查询条件是DateTime_Start.Date,和DateTime_End.Date.要查找这个时间段的,好麻烦...有交集的情况都要考虑...查询语句要怎么写呢?我以前写的,字段只有一个'时间'点,查询条件字符串是: m_timefilter:='时间>='+DateToStr(DateTime_Start.Date)+' and 时间<='+DateToStr(DateTime_End.Date);现在查询结果是个时间段...我被弄糊涂了.

解决方案 »

  1.   


    'select * from table where 时间 between #'+ FormatDateTime('yyyy-mm-dd',DateTime_Start.Date)+'# and #'+FormatDateTime('yyyy-mm-dd',DateTime_End.Date)+'#'
      

  2.   

    好象要分4种情况是不?(开始时间 >= Start.Date and 开始时间 <= End.Date)or (结束时间 >= Start.Date and 结束时间 <= End.Date) or (Start.Date >= 开始时间 and Start.Date <= 结束时间) or (End.Date >= 开始时间 and End.Date <= 结束时间)对不?
      

  3.   

    你是想取在"开始时间段"和"结束时间段"内的记录吧
    违码:where 开始时间<=时间1<=开始时间 and 结束时间<=时间2<=结束时间
      

  4.   

    //Dt101,Dt102:TDateTimePicker;
    //建议使用Checked属性,客户爱取什么范围自己选去    if Dt101.Checked then//开始日期
            Sql.Add('And TA007 >= '''+FormatDateTime('yyyymmdd',Dt101.Date)+'''');
        if Dt102.Checked then
            Sql.Add('And TA007 <= '''+FormatDateTime('yyyymmdd',Dt102.Date)+'''');
      

  5.   


    SELECT * FROM 培訓表 WHERE 開始時間 >= DateTime_Start.Date 
                          and 開始時間 <= DateTime_End.Date
                          and 結束時間 >= DateTime_Start.Date
                          and 結束時間 <= DateTime_End.Date
      

  6.   

    交集? 只要Dt101,Dt102有一个在A:2007-8-1到B:2008-1-10这个时间内,那肯定就有交集了么,
    (A<=Dt101.Date<=B) or (B<=Dt102.Date<=B)
      

  7.   

    (A <=Dt101.Date <=A) or (B <=Dt102.Date <=B)
      

  8.   

    我想明白了....浪费大家时间了..
    开始时间<=End.Date and 结束时间 >= Start.Date就行了...谢谢大家了=.=
      

  9.   

    (A <=Dt101.Date <=A) or (B <=Dt102.Date <=B) or (Dt101.Date<=A and B<=Dt102.Date)
    再加个[Dt101,Dt102]包含[A,B]的情况,没别的交集情况了