SQL 报表 生成月份临时表

 1 if OBJECT_ID('tempdb..#temptblAllYearMonth') is not null
 2 drop table #temptblAllYearMonth
 3 
 4 declare @StartDate DATE = '20210101'
 5 declare @EndDate DATE = '20211201';
 6 
 7 WITH cte as (
 8     select @StartDate dateCol union all select DATEADD(MONTH, 1, dateCol)
 9     from cte where dateCol < @EndDate
10 )
11 select CONVERT(varchar(6), dateCol,  112) dateCol, 0 as ToTal
12 
13 into #temptblAllYearMonth from cte;
14 
15 --查询数据
16 select * from #temptblAllYearMonth

SQL 报表 生成月份临时表

上一篇:spring boot 集成swagger2


下一篇:java计算两个日期的天数间隔