按月查询

xiaxiasmile 2009-07-07 04:39:58
shijian Username
2009-7-6 0:00:00 张三
2009-6-6 0:00:00 李四
2009-7-8 0:00:00 王五
2009-6-6 0:00:00 个个
现从前台页面DropDownList中取一个数如:200907进行查询
查询结果将2009年7月所有记录
shijian UserName
2009-7-6 张三
2009-7-8 王五
...全文
30 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
feixianxxx 2009-07-11
  • 打赏
  • 举报
回复
select * from tt where format(shijian,'yyyymm')='200907'
select * from tt where convert(varchar(7),shijian)='200907'
ACMAIN_CHM 2009-07-08
  • 打赏
  • 举报
回复

既然你能够用前台程序进行处理则建议

varMonth = '200907'
生成如下SQL语句。
select * from yourTable where shijian between #2009-07-01# and #2009-07-31#


当然如果数据不多对效率要求不敏感的情况下,也可以用
select * from yourTable where year(shijian)=2009 and month(shijian)=7;

select * from yourTable where year(shijian)*100+month(shijian)=200907

select * from yourTable where format(shijian,'yyyymm')='200709'


效率递减,以保留日期型进行between and 为上, format(shijian,'yyyymm') 为最差。

wwwwb 2009-07-07
  • 打赏
  • 举报
回复
select * from tt where format(shijian,'yyyymm')='200907'

7,714

社区成员

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

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