如何从表table 中查询出这样的记录???name   shi_date    end_date
客户   2006-5-1    2006-6-1
客户   2006-6-1    2006-7-1
记者   2006-8-1    2006-8-3Edit1,Edit2中的文本都为日期如何用ADOQuery1的sql语句选出Edit1.Text在shi_date与end_date之间或Edit2.Text在shi_date与end_date之间,SQL语句应如何写???这样写查询不出记录
--------------------------------------------------------------------------
ADOQuery1.Close;
ADOQuery1.SQL.Add('select * from table where  '''+FormatDateTime('yyyy-m-d',StrToDate 
     (Edit1.Text))+''' >= shi_date and '''+FormatDateTime('yyyy-m-d',StrToDate 
     (Edit1.Text))+''' <=end_date or  '''+FormatDateTime('yyyy-m-d',StrToDate(Edit2.Text))
      +''' >= shi_date and '''+FormatDateTime('yyyy-m-d',StrToDate(Edit2.Text))+''' 
      <=end_date ');
ADOQuery1.Parameters.ParamByName('c_id').Value:=Edit3.Text;
ADOQuery1.Parameters.ParamByName('p_id').Value:=Edit4.Text;
ADOQuery1.Open;
--------------------------------------------------------------------------
这样写对不对,应该怎样写???

解决方案 »

  1.   

    query.sql.text:='select * from table1 where (shi_date<'''+Trim(edit1.text)+''' and end_date>'''+Trim(Edit1.text)+''')'+' or (shi_date<'''+Trim(Edit2.text)+''' and end_date>'''+Trim(edit2.text)+''')'
      

  2.   

    ADOQuery1.SQL.Add('select * from table where  ('''+FormatDateTime('yyyy-m-d',StrToDate 
         (Edit1.Text))+''' BETWEEN shi_date and end_date)or('''+FormatDateTime('yyyy-m-d',StrToDate(Edit2.Text))
          +''' BETWEEN shi_date and end_date)');