根据日期计算星期几
declare @weekDay int=0, @weekStr varchar(10)='',--星期几 @startDate datetime ='2022-10-03', @Endate datetime ='2022-10-09'
declare @WeekTable table (Date datetime ,weekStr varchar(10),weekDay int) while (@startDate<=@Endate) begin set @weekDay=datepart(weekday,@startDate) set @weekStr=DATENAME(weekday,@startDate) insert into @WeekTable values (@startDate,@weekStr,@weekDay) set @startDate=DATEADD(dd,1,@startDate) end select * from @WeekTable
返回结果