表a中有两个日期字段:starttime,endtime
其中有条记录为:    2007-1-1, 2008-1-1现在想检索包含2007-11-1到2007-12-1时间段的记录,应该怎么写?

解决方案 »

  1.   

    select * from a where starttime>=2007-11-1 and endtime <=2007-12-1 --全包含
    select * from a where starttime<=2007-12-1 or endtime>=2007-11-1 --部分包含
      

  2.   

    select * from a where starttime between '2007-11-1' in '2008-1-1'
    and endtime<'2008-1-1'
      

  3.   

    select * from table where starttime<2007-11-1 and endtime > 2007-12-1
      

  4.   

    select * from a where starttime>='2007-11-1' and endtime <='2007-12-1' 
    select * from a where starttime<='2007-12-1' or endtime>='2007-11-1'
      

  5.   

    select * from 表 where starttime>='2007-11-1' and endtime <='2007-12-1'
      

  6.   

    晕,不知道怎么会出现上面那个。开始时间小于,结束大于,就包括了。select * from table where starttime<'2007-11-1' and endtime >'2007-12-1' 
      

  7.   

    判断两个时间在已有的区间内 
    public DataTable CheckDate(string  checkBeginTime,string checkEndTime,string fliter)
            ...{
                System.Text.StringBuilder strSql = new System.Text.StringBuilder();
                strSql.Append("select NoteID,NoteTitle,CreateDate,EndDate from tblNetSplitNoteData" +
                               " where ((CreateDate>='"+checkBeginTime+"' and CreateDate<='"+checkEndTime+"')"+
                               " or (EndDate>='"+checkBeginTime+"' and EndDate<='"+checkEndTime+"')"+
                               " or '" + checkBeginTime + "' between CreateDate and EndDate) ");
                if (fliter != "")
                ...{
                    strSql.Append(fliter);
                }
                DataTable dt = this.DatabaseAccess.ExecuteDataset(strSql.ToString()).Tables[0];
                return dt;          
        }       
      

  8.   

    select * from a where starttime<=2007-11-1 and endtime  >=2007-12-1
      

  9.   


    没错,前半段我也是这样写的,再加上个or(checkEndTime + "' between CreateDate and EndDate) 似乎就完美了