例如查询 2012-1-5 到 2012-11-3 之间所有的月份

 

declare @begin datetime,@end datetime
set @begin='2012-1-5'
set @end='2012-11-3'

declare @months int
set @months=DATEDIFF(month,@begin,@end)
select convert(varchar(7),DATEADD(month,number,@begin) ,120) AS 月份
from master.dbo.spt_values 
where type='p' AND number<=@months

 

结果

 

SQL Server中获取指定时间段内的所有月份

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-12-03
  • 2021-11-29
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-29
猜你喜欢
  • 2021-12-03
  • 2022-12-23
  • 2022-02-08
  • 2022-12-23
  • 2022-02-01
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案