我有一个存储函数,它应该计算出我的工资单周开始日期。哪个是“星期四” 但是我的存储过程总是将我的开始日期设为“星期五” 我的声明和设置函数有什么问题?我希望我的 StartWeekDay 为“Thursday”...“lStartday”在帐户表中设置为“5”我的代码如下:
DECLARE @StartWeekDay int
SET @StartWeekDay = (Select lStartDay From Account Where lLocationID = 1)
DECLARE @CurrentDate DateTime
SET @CurrentDate = GetDate()
DECLARE @CurrentWeekDay int
SET @CurrentWeekDay = DATEPART(dw,@CurrentDate)
DECLARE @Diff int
SET @Diff = @StartWeekDay - @CurrentWeekDay
SET @Diff = Case When @Diff > 0 Then -6 When @Diff = 0 Then 0 Else @Diff End
--
DECLARE @DaysToStart int
SET @DaysToStart = (DatePart(dw,@CurrentDate) - @StartWeekDay)
IF @DaysToStart <= .1
BEGIN
SET @DaysToStart = @DaysToStart + 7
END
DECLARE @myStartWeekDate DateTime
--SET @myStartWeekDate = dbo.DateOnly(DATEADD(d,@Diff,@CurrentDate))
SET @myStartWeekDate = Convert(nvarchar,DateAdd(d,-@DaysToStart,@CurrentDate),101) -- getting DATE only
--