本人在写一人事系统,需要到一个功能:统计生日到期职工,其中提供用户查询某时间段(只含月日)过生日职工的功能,具体如下;
职工表:Employee
生日字段:Employee_Birthday (如:'2005-04-06'格式的字符串)
如:查04月01日至06月13日之间过生日员工 ,
开始时间:StartDateTimePicker.date
结束时间:StopDateTimePicker.date
我写的如下:
        with ADOQAtTerm do
        begin
          close;
          sql.Clear;
          sql.Add('select *');
          sql.Add('From Employee');
          sql.Add('Where Employee_Birthday > year(Employee_Birthday)' + formatdatetime('-mm-dd', StartDateTime.Date) + '''');
          sql.Add('and Employee_Birthday < year(Employee_Birthday)' + formatdatetime('-mm-dd', StopDateTime.date) + '''');
          open;
================
year(Employee_Birthday) 好象是返回一个数值,所以连不了后面的字符

解决方案 »

  1.   

    sql.Add('Where Employee_Birthday >left(Employee_Birthday,4)' + formatdatetime('-mm-dd', StartDateTime.Date) + '''');
              sql.Add('and Employee_Birthday <left(Employee_Birthday,4)' + formatdatetime('-mm-dd', StopDateTime.date) + '''');
      

  2.   

    year(Employee_Birthday)
    是返回数值型的用formatdatetime是返回字符
      

  3.   

    回复人: fengzhengren(风筝) ( ) 信誉:97  
    楼上好像落下一种情况,就是从大月份到小月份的情况。
    如今年10月1日到明年4月1日。
    也就是介于10月1日到4月1日之间的。
    ==========
    这个不是问题,我再分成两段就行了。。
      

  4.   

    回复人: gzmhero(hihihi) ( ) 信誉:110  2005-04-27 08:54:00  得分: 0  
     
     
       sql.Add('Where Employee_Birthday >left(Employee_Birthday,4)' + formatdatetime('-mm-dd', StartDateTime.Date) + '''');
              sql.Add('and Employee_Birthday <left(Employee_Birthday,4)' + formatdatetime('-mm-dd', StopDateTime.date) + '''');
    =========================================
    运行不通过,操作符:'Employee_Birthday <left(Employee_Birthday,4)-04-20'掉失
      

  5.   

    没仔细看,呵呵。这样再试试:sql.Add('Where right(Employee_Birthday,5)>formatdatetime('-mm-dd', StartDateTime.Date) + '''');
    sql.Add('and right(Employee_Birthday,5)<formatdatetime('-mm-dd', StopDateTime.date) + '''');
      

  6.   

    上面多个'-'号,这样的:sql.Add('Where right(Employee_Birthday,5)>formatdatetime('mm-dd', StartDateTime.Date) + '''');
    sql.Add('and right(Employee_Birthday,5)<formatdatetime('mm-dd', StopDateTime.date) + '''');
      

  7.   

    gzmhero(hihihi) ( ) 信誉:110 
    ======
    access不支持Right函数
      

  8.   

    我在SQL Explorer里试的。。,我用的是ACCESS
      

  9.   

    怎么不在ACCESS里实践一下,Access里可以用的。
      

  10.   

    with adoquery1 do begin
      Close;
      SQL.Clear;
      SQL.Add('select * from Employee where Employee_Birthday>=:startrq and Employee_Birthday <=:endrq');
      Parameters.ParamByName('startrq').Value:=formatdatetime('mm-dd',form1.DateTimePicker1.Date);
      Parameters.ParamByName('endrq').Value:=formatdatetime('mm-dd',form1.DateTimePicker2.Date);
      Open;
    end;
    ///试试看....
      

  11.   

    1 回复人: gzmhero(hihihi) ( ) 信誉:110  2005-04-27 11:11:00  得分: 0  
     
     
       怎么不在ACCESS里实践一下,Access里可以用的。
    ==============
    程序通不过啊,2
    回复人: gxgyj(杰克.逊_Discovery) ( ) 信誉:94  2005-04-27 11:22:00  得分: 0  
     
     
       with adoquery1 do begin
      Close;
      SQL.Clear;
      SQL.Add('select * from Employee where Employee_Birthday>=:startrq and Employee_Birthday <=:endrq');
      Parameters.ParamByName('startrq').Value:=formatdatetime('mm-dd',form1.DateTimePicker1.Date);
      Parameters.ParamByName('endrq').Value:=formatdatetime('mm-dd',form1.DateTimePicker2.Date);
      Open;
    end;
    ///试试看....
      你的道理不哦,Employee_Birthday是'2005-04-06'形式的,跟一个'04-20'来怎么比较啊
    0
      

  12.   

    是语法有问题,引号没匹配。right是可以用的。sql.Add('Where right(Employee_Birthday,5)>'''+formatdatetime('mm-dd', StartDateTime.Date) + '''');
    sql.Add('and right(Employee_Birthday,5)<'''+formatdatetime('mm-dd', StopDateTime.date) + '''');
      

  13.   

    with adoquery1 do begin
      Close;
      SQL.Clear;
      SQL.Add('select * from Employee where (month(Employee_Birthday)>=:start1 and day(Employee_Birthday)>=:start2) and (month(Employee_Birthday)<=:end1 and day(Employee_Birthday)<=:end2) ');
      Parameters.ParamByName('start1').Value:=formatdatetime('mm',form1.DateTimePicker1.Date);
      Parameters.ParamByName('start2').Value:=formatdatetime('dd',form1.DateTimePicker1.Date);
      Parameters.ParamByName('end1').Value:=formatdatetime('mm',form1.DateTimePicker2.Date);
      Parameters.ParamByName('end2').Value:=formatdatetime('dd',form1.DateTimePicker2.Date);
      open;
    end;
      

  14.   

    with AdoQuery1 do
    begin
      Close;
      SQL.Text :=
        'Select * from Employee '
        'where right(Employee_Birthday,5) between '+
         #39 + FormatDateTime('mm-dd', StartDateTimePicker.Date) + #39 +
        ' and ' +
         #39 + FormatDateTime('mm-dd', StopDateTimePicker.Date) + #39;
      Open;
    end;
      

  15.   

    回复人: gzmhero(hihihi) ( ) 信誉:110  2005-04-27 12:18:00  得分: 0  
     
     
       是语法有问题,引号没匹配。right是可以用的。sql.Add('Where right(Employee_Birthday,5)>'''+formatdatetime('mm-dd', StartDateTime.Date) + '''');
    sql.Add('and right(Employee_Birthday,5)<'''+formatdatetime('mm-dd', StopDateTime.date) + '''');
      
     ========
    用这个方法可以了,谢谢!!
    结帖放分了。。