能否提供程序代碼參考.我用的以下方法,可是隻能查到2001的,2001/10或2001/10/24就查不到了.
function get_year:string;//年的函數
var
  str_year,str_temp:string;
begin
  str_year:=form1.ComboBox1.text;
  if form1.ComboBox1.Text='' then
    str_temp:=''
  else
    str_temp:=str_year;
  result:=str_temp;
end;function get_month:string;//月的函數
var
  str_month,str_temp:string;
begin
  str_month:=form1.combobox2.text;
  if form1.combobox2.text=''then
    str_temp:=get_year//調用年
  else
    if get_year='' then
      str_temp:=str_month
    else
      str_temp:=get_year+'/'+str_month;
  result:=str_temp;
end;function get_all:string;//日的函數
var
  str_day,str_temp:string;
begin
  str_day:=form1.ComboBox3.Text;
  if form1.ComboBox3.text='' then
    str_temp:=get_month//調用年月
  else
    if get_month='' then
      str_temp:=str_day
    else
      str_temp:=get_month+'/'+str_day;
  result:=str_temp;
end;procedure TForm1.Button1Click(Sender: TObject);//查詢按鈕
var
  str:string;
begin
    str:=get_all;
    with adoquery1 do
    begin
      close;
      sql.Clear;
      sql.Add('select * from employee where employee_indate like '+'''%'
+trim(str)+'%'+'''');
      open;
    end;
    edit1.Text:=str;
    form1.Print;
end;

解决方案 »

  1.   

    你的employee_indate是日期型字段?数据库Sql Server的命令如下:
    SELECT * FROM EMPLOYEE WHERE EMPLOYEE_INDATE = ConVert(DateTime, ' + #39 + TRIM(STR) + #39 + ',101)
    ----------------------------------------------------------------
    Wild Deer
      

  2.   

    sql.Add('select * from employee where employee_indate like '+'''%'
    +trim(str)+'%'+'''');
    这句话有问题,如果你用的是SQLServer数据库,可以这样改:
    sql.Add('select * from employee where convert(varchar,employee_indate,111) like '+'''%'
    +trim(str)+'%'+'''');
      

  3.   

    sql.add('select * from employee where convert(varchar,employee_indate) like'+'''%'+trim(str)+'%'+'''');
      

  4.   

    你的函数有个问题,就是当月为空的时候,你查询到的是年/日 ,而程序却还是认为查询到的是年月,这明显就是错误了。其实你要调用年月日写这么多函数太麻烦了。
    直接通过判断是否为空,进行年月日的组合就Ok了!
    ================================================================CSDN 论坛助手 Ver 1.0 B0402提供下载。 改进了很多,功能完备!★  浏览帖子速度极快![建议系统使用ie5.5以上]。 ★  多种帖子实现界面。 
    ★  保存帖子到本地[html格式]★  监视您关注帖子的回复更新。
    ★  可以直接发贴、回复帖子★  采用XML接口,可以一次性显示4页帖子,同时支持自定义每次显示帖子数量。可以浏览历史记录! 
    ★  支持在线检测程序升级情况,可及时获得程序更新的信息。★★ 签名  ●  
         可以在您的每个帖子的后面自动加上一个自己设计的签名哟。Http://www.ChinaOK.net/csdn/csdn.zip
    Http://www.ChinaOK.net/csdn/csdn.rar
    Http://www.ChinaOK.net/csdn/csdn.exe    [自解压]
      

  5.   

    你要是用的Sql Server,你用sqlserver里的时间、日期函数会很方便
    函数:http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_fa-fz_2c1f.asp