日期:2014-05-18 浏览次数:20638 次
declare @Start varchar(10) declare @End varchar(10) set @Start='2012-04' set @End='2013-09' --实现跨年: select convert(varchar(7),DATEADD(MM,number,cast(@Start+'-01' as date)),120) as Year_Month from master..spt_values where number between 0 and DATEDIFF(MM,cast(@Start+'-01' as date),cast(@End+'-01' as date)) and type='p' /* Year_Month ------------------ 2012-04 2012-05 2012-06 2012-07 2012-08 2012-09 2012-10 2012-11 2012-12 2013-01 2013-02 2013-03 2013-04 2013-05 2013-06 2013-07 2013-08 2013-09 */