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 报表 生成月份临时表

SQL 报表 生成月份临时表

上一篇:NAVICAT 连接ORACLE 出现ORA06413 连接未打开


下一篇:pg添加链接IP白名单————PostgreSQL在配置文件pg_hba.conf添加IP操作