-- create by zhouxin -- create time 2009-9-14-15 DECLARE @Year nvarchar(4) DECLARE @YearMonth nvarchar(7) --月份 DECLARE @strTop nvarchar(200) DECLARE @ForI INT,@ForYear INT ,@MaxDay INT DECLARE @RowX INT --行位置 DECLARE @strWeekDayList nvarchar(20) DECLARE @strPrint nvarchar(300) -- ====================================== SET @Year='2009' --请在这里输入年份 -- ====================================== SET @strTop= '日'+char(9)+'一'+char(9)+'二' +char(9)+'三'++char(9)+'四'++char(9)+'五'++char(9)+'六' +char(13)+ '───────────────────────────' SET @strWeekDayList='日一二三四五六' SET @ForYear=1 WHILE @ForYear<=12 --1月份至月份 BEGIN SET @YearMonth=@Year + '-' +CAST( @ForYear AS nvarchar(2)) SET @MaxDay=DAY(DATEADD(Day,-1,DATEADD(Month,1,@YearMonth+'-01'))) SET @RowX=CHARINDEX(RIGHT(DATENAME(WeekDay,@YearMonth+'-01'),1),@strWeekDayList)-1 SET @strPrint='' SET @ForI=1 WHILE @ForI<=@RowX --构造号的位置 BEGIN SET @strPrint=@strPrint+CHAR(9) SET @ForI=@ForI+1 END SET @ForI=1 WHILE @ForI<=@MaxDay --构造号到月底的位置 BEGIN SET @strPrint=@strPrint+CAST(@ForI AS nvarchar(2)) +Char(9) SET @RowX=@RowX+1 SET @ForI=@ForI+1 IF (@RowX%7=0) BEGIN SET @RowX=0 SET @strPrint=@strPrint+CHAR(13) END END SET @ForYear=@ForYear+1 -- 打印输出一个月的结果 PRINT '━━━━━━━━━━━━━━━━━━━━━━━━━━━' PRINT +Char(9)++Char(9)+' '+@YearMonth+CHAR(10) PRINT @strTop PRINT @strPrint +CHAR(10) END
SQL语句生成日历
最新推荐文章于 2021-10-19 15:17:04 发布