sqlserver2000下有个表(t_oa_sys_account)
其中有个字段(birthday)类型(datetime)里面存放着yyyy-mm-dd格式日期我只想获得当前系统日期,然后在表里查询是否有和当前日期相匹配的(不比较年)
如果有就将此条记录name字段的姓名提出来存放到一个变量里,基本过程
就这样,希望哪个高手将这段代码写出来让小弟学习一下。小弟将另开帖子给这位兄弟100分。

解决方案 »

  1.   

    select *
    from Table
    where MONTH (getdate())=MONTH (birthday)
         And Day(getdate())=Day(birthday)
      

  2.   

    select *
    from t_oa_sys_account
    where MONTH (getdate())=MONTH (birthday)
         And Day(getdate())=Day(birthday)
      

  3.   

    select *
    from Table
    where MONTH (getdate())=MONTH (birthday)
         And Day(getdate())=Day(birthday)
      

  4.   

    var
      qryf:Tadoquery;
      str_Name:string;  qryf:=TADOquery.create
      try 
        qryf.connection:=
        qryf.close;
        qryf.sql.clear;
        qryf.sql.add('select *
                   from t_oa_sys_account
                   where MONTH (getdate())=MONTH (birthday)
                   And Day(getdate())=Day(birthday)');
        qryf.open;
        if qryf.RecordCount>0 then
           str_Name:=qryf.fieldbyname('name').AsString;
      finally
        qryf.close;
        qryf.free;
      end;
      

  5.   

    select name from t_oa_sys_account where substring(birthday,6,5)=left(convert(varchar(100),getdate(),110),5)
      

  6.   

    用这个组件ADODataSet1在程序里应该怎么写可以运行此SQL语句并将结果保存到变量里?
      

  7.   

    兄弟建议你:找点Delphi数据库编程的书看看
      

  8.   

    select name from t_oa_sys_account
         where MONTH (getdate())=MONTH (birthday)
                              And Day(getdate())=Day(birthday)
      

  9.   

    var
     str_Name:string;
    begin
    with ADODataSet1 do
    begin
      close;
      CommandText:= 'select * '
                   +'from Table1 '
                  +' where MONTH (getdate())=MONTH (birthday)'
                   +'And Day(getdate())=Day(birthday)');
        Open;
        if RecordCount>0 then
      str_Name:=fieldbyname('name').AsString;
    end;
    end;如果记录多可以考虑用数组
    不过也可以加查询结果保存到一个临时表
    在处理完后后加表删除,基本代码如下:
    with ADODataSet1 do
    begin
      close;
      CommandText:= 'select * Into Table_New'
                   +'from Table1 '
                  +' where MONTH (getdate())=MONTH (birthday)'
                   +'And Day(getdate())=Day(birthday)');
        Open;
      {处理具体事件}
     close;
     commandText:='drop table Table_New';
     open;
    end;
     
      

  10.   

    1 与数据库连接。设置好ADODataSet1的ConnectionString;
    2 设置ADODataSet1的CommandText
      select * from t_oa_sys_account where MONTH (getdate())=MONTH (birthday)
         And Day(getdate())=Day(birthday)
      将上面的SQL语句赋个它
    3 ADODataSet1.Active=True;
    4 if ADODataSet1.RecordCount>0 then
      变量:=ADODataSet1.FieldByName('Name').AsString;