求一条SQL语句,查询出本年本月的所有数据,这样的语句怎么写?

海里猿人 2009-04-16 07:02:17
求一条SQL语句,查询出本年本月的所有数据,这样的语句怎么写?
...全文
1100 22 打赏 收藏 转发到动态 举报
写回复
用AI写文章
22 条回复
切换为时间正序
请发表友善的回复…
发表回复
w398687283 2009-08-19
  • 打赏
  • 举报
回复
mark
htl258_Tony 2009-04-17
  • 打赏
  • 举报
回复
楼主是要生成日期数据还是查找表数据?
  • 打赏
  • 举报
回复
select * from tb where datediff(mm,getdate(),日期)=0
usher_gml 2009-04-17
  • 打赏
  • 举报
回复
select * from tb where datediff(mm,coldate,getdate())=0
zzxap 2009-04-17
  • 打赏
  • 举报
回复
select * from tb where datediff(mm,coldate,getdate())=0 当月

select * from tb where datediff(year,coldate,getdate())=0 当年
仙道彰 2009-04-17
  • 打赏
  • 举报
回复
上面写错了。。。。
select * from tb where 日期 >= CONVERT(char(5),@dt,120)+'1-1'
and 日期 <= CONVERT(char(5),@dt,120)+'12-31'
仙道彰 2009-04-17
  • 打赏
  • 举报
回复
select * from tb where 日期 => CONVERT(char(5),@dt,120)+'1-1'
and 日期 <= CONVERT(char(5),@dt,120)+'12-31'
wwle1985 2009-04-17
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 mugua604 的回复:]
SQL code

select * from tableName where datediff(mm,col,getdate())=0
[/Quote]

这条比较简单实用
wxg22526451 2009-04-17
  • 打赏
  • 举报
回复
select * from tb where datediff(mm,coldate,getdate())=0
修炼成精 2009-04-17
  • 打赏
  • 举报
回复
如果数据量很大,注意查询效率 对日期建立索引 ,然后查询
dj3688 2009-04-16
  • 打赏
  • 举报
回复

select * from tableName where (datediff(yyyy,col,getdate())=0 and datediff(mm,col,getdate())=0)
CHIC250 2009-04-16
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 xiequan2 的回复:]
SQL code
select * FROM tb
WHERE Year(日期)=year(getdate()) and month(日期)=month(getdate())
[/Quote]
同意!
lg3605119 2009-04-16
  • 打赏
  • 举报
回复

select * from tb where year(filed) = year(getdate()) and month(filed) = month(getdate())
mugua604 2009-04-16
  • 打赏
  • 举报
回复


select * from tableName where datediff(mm,col,getdate())=0
htl258_Tony 2009-04-16
  • 打赏
  • 举报
回复
-->本年:
select dateadd(dd,number,datename(yy,getdate())+'0101')
from master..spt_values
where type='p'
and number<=datediff(dd,datename(yy,getdate())+'0101',datename(yy,getdate())+'1231')
-->本月:
select dateadd(dd,number,datename(yy,getdate())+datename(mm,getdate())+'01')
from master..spt_values
where type='p'
and number<day(dateadd(mm,1,getdate())-day(getdate()))
lfywy 2009-04-16
  • 打赏
  • 举报
回复
select * FROM tb
WHERE Year(日期)=year(getdate()) and month(日期)=month(getdate())
htl258_Tony 2009-04-16
  • 打赏
  • 举报
回复
-->本年:
select dateadd(dd,number,datename(yy,getdate())+'0101')
from master..spt_values
where type='p'
and number<=datediff(dd,datename(yy,getdate())+'0101',datename(yy,getdate())+'1231')
xiequan2 2009-04-16
  • 打赏
  • 举报
回复

select * FROM tb
WHERE Year(日期)=year(getdate()) and month(日期)=month(getdate())

sdhdy 2009-04-16
  • 打赏
  • 举报
回复

select * from tb where datediff(mm,coldate,getdate())=0
liangCK 2009-04-16
  • 打赏
  • 举报
回复
SELECT *
FROM tb
WHERE 日期 >= DATEADD(day,-DATEPART(day,GETDATE())+1,GETDATE())
AND 日期 < DATEADD(month,1,CONVERT(VARCHAR(7),GETDATE(),120)+'-1')
加载更多回复(2)

34,588

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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