如何动态的查询某一段时期内的数据?

sdzbbz 2006-11-20 11:13:19
数据库中的日期格式为:2006-9-1
现在想要查询每个月的数据,比如说查询10月份的数据,我用的下面语句:
ADOQuery1.Close;
ADOQuery1.SQL.Clear;
sql_text := 'select * from 工图 where 日期>=#2006-10-01# and 日期<#2006-11-01#';
ADOQuery1.SQL.Add(sql_text);
ADOQuery1.Prepared;
ADOQuery1.Open;
这样确实能把10月份的单独列出来,可是我想任意查找某个月的,就在窗体上设了一个edit1,把想要查找的月份写在edit1里,根据edit1的内容来查找,请问这时的语句该怎么写啊?谢谢大家!
...全文
230 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
changechange 2006-11-23
  • 打赏
  • 举报
回复
select * from 工图 where year(日期)=2006 and month(日期)=10
sdzbbz 2006-11-21
  • 打赏
  • 举报
回复
多谢wangtiecheng(不知不为过,不学就是错!) 的提醒,确实也对,我应该把年份也加上,要不然的话,一年后这个软件就不能用了,呵呵
OracleRoob 2006-11-20
  • 打赏
  • 举报
回复
应该还有年份吧?只有月份的话,去年的同一个月份的不也查出来了?
OracleRoob 2006-11-20
  • 打赏
  • 举报
回复
edit1里只放月份?
OracleRoob 2006-11-20
  • 打赏
  • 举报
回复

sql_text:="select * from 工图 where format(日期,'yyyymm')=format(" + edit1.txt + ",'yyyymm')";
wwwwb 2006-11-20
  • 打赏
  • 举报
回复
1、用DELPHI函数转换;
2 'select * from 工图 where 日期>=#2006-10-01# and 日期<#2006-11-01#';
->
'select * from 工图 where 日期>=format('+edit1.txt+',"yyyy-mm-dd")'+
'and 日期<format('+edit2.txt+',"yyyy-mm-dd")';

linyany 2006-11-20
  • 打赏
  • 举报
回复
Left(Format([日期],"yyyy-mm-dd"),5) & edit1 & Right(Format([字段4],"yyyy-mm-dd "),3)

7,714

社区成员

发帖
与我相关
我的任务
社区描述
Microsoft Office Access是由微软发布的关系数据库管理系统。它结合了 MicrosoftJet Database Engine 和 图形用户界面两项特点。
社区管理员
  • Access
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧