sql语句日期查询 。

yanyue_malongjun 2011-05-12 01:01:44
有个表,表名为userlog,有一列为inputdate是日期变量,日期格式是2009-10-10 12:00:00
如果我想查询这个表中2009年10月的内容,SQL语句该如何编写?


就是知识查询这个月的数据。
...全文
487 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
小童 2011-05-12
  • 打赏
  • 举报
回复
select * from userlog where convert(varchar(6),inputdate,112)='200910'
jiangban1 2011-05-12
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 naonaoye 的回复:]
select * from userlog where inputdate like '2009-10%'
[/Quote]
这个貌似不行 如果类型是varchar 还可以 要是Data的话就不行啦
z050301402 2011-05-12
  • 打赏
  • 举报
回复
结帖率:0.00%
.......................................................
zhuxueliao 2011-05-12
  • 打赏
  • 举报
回复

应该解决了吧
jeje 2011-05-12
  • 打赏
  • 举报
回复
select * from userlog where inputdate between '2009-10-01' and '2009-10-31'


格桑花 2011-05-12
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 work_fei 的回复:]
select * from userlog where year(inputdate)='2009' and month(inputdate)='10'
[/Quote]

+++
IT0329 2011-05-12
  • 打赏
  • 举报
回复
哎哟,不错哦!
work_fei 2011-05-12
  • 打赏
  • 举报
回复
select * from userlog where year(inputdate)='2009' and month(inputdate)='10'
play1982 2011-05-12
  • 打赏
  • 举报
回复
datediff(month,'2009-10-10','2009-10-01')=0
白云任去留 2011-05-12
  • 打赏
  • 举报
回复
方法不限一种,除了像楼上3楼的,还有如:
select * from userlog where convert(varchar(7),inputdate,23)='2009-10'
select * from userlog where datepart(yy,inputdate)='2009' and datepart(m,inputdate)='10'
...
不懂 2011-05-12
  • 打赏
  • 举报
回复

select * from userlog where inputdate>=CONVERT(datetime,CONVERT(varchar(7),GETDATE(),111)+'-01') and inputdate<CONVERT(datetime,CONVERT(varchar(7),Dateadd(MONTH,1,GETDATE()),111)+'-01')

只要把GETDATE()换成你要查询的时间就可以了。
yubofighting 2011-05-12
  • 打赏
  • 举报
回复

select * from userlog where inputdate between '2009-10-01' and '2009-10-31'

日期类型可以直接这样使用
zhanglong_longlong 2011-05-12
  • 打赏
  • 举报
回复
select * from userlog where dataname(year,inputdate)=2009 and dataname(month,inputdate)=10
naonaoye 2011-05-12
  • 打赏
  • 举报
回复
select * from userlog where inputdate like '2009-10%'

62,041

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

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