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