SQL Server 创建一年的日期

SQL Server  创建一年的所有日期,并计算周几


select WorkDate,DateType,IsWorkDay,Remark INTO [dbo].[HR_WorkDayList] from 

(SELECT convert(char(10), DATEADD(dd, number, '2020-01-01'),120) AS WorkDate, 
datename(weekday,convert(char(10), DATEADD(dd, number, 2020-01-01),120)) as DateType, 
case when datename(weekday,convert(char(10), DATEADD(dd, number, 2020-01-01),120))<>'星期六' and datename(weekday,convert(char(10), DATEADD(dd, number, 2023-08-11),120))<>'星期日' then 1 else 0 end as IsWorkDay,
'' as Remark
FROM   master.dbo.spt_values  as spt
WHERE   type = 'p' AND number <= DATEDIFF(DAY, '2020-01-01', '2020-12-31')) as SourceTable

你可能感兴趣的:(SQL Server 创建一年的日期)