如何在sql语句中查询字段date中所示时间距今一个月内的数据?(50分)

  • 主题发起人 主题发起人 base7
  • 开始时间 开始时间
B

base7

Unregistered / Unconfirmed
GUEST, unregistred user!
sigh,编来编去的越编越糊涂了
此处先谢过了
 
select * from yourtable where (month(date)-month(yourdatefield)=1 and
year(date)=year(yourdatefield) ) or (month(date)=1 and month(yourdatefield)=12 and
year(date)-year(yourdatefield)=1)
 
select * from yourtable where :udate-udatefield<=30
query.parambyname('udate').asdatetime:=strtodatetime(edit1.text);
 
设TheDate为日期型字段

Var
NowDate:TDateTime;
LastDate:TDateTime;
...
NowDate:=? //自己设定 strtodatetime('19999-5-7');
LastDate:=NowDate-30 //

Query.close;
Query.SQL:=' Select * from UTable
where (TheDate>:LastDate) and (TheDate<=:NowDate)'
Query.ParamByName('LastDate').AsDatetime:=LastDate;
Query.ParamByName('NowDate').AsDatetime:=NowDate;
Query.Open;
...

OK!
 
试了你们两个的解法,怎么好象都有问题?
To:g622
你的month(date)的用法好象不承认?
To:Hjking
呵呵,你的udate和udatefield把我都搞晕了
我觉得这里的udatefield是不是应该采用系统的日期?
而udate是数据库本身有的,也用不着从edit里读的...
 
多人接受答案了。
 
后退
顶部