如何将以下逻辑放入SQL Server用于创建会计周数的格式中?
if (datepart(week,getdate())-4) <= 0 then (datepart(week,getdate())+49) else (datepart(week,getdate())-4)
答案 0 :(得分:1)
CASE声明应该有效:
CASE
WHEN datepart(week,getdate())-4) <= 0
THEN datepart(week,getdate())+49
ELSE
datepart(week,getdate())-4
END
答案 1 :(得分:0)
您可以使用case
表达式:
SELECT CASE WHEN (DATEPART(WEEK, getdate()) - 4) <= 0
THEN DATEPART(WEEK, getdate()) + 49
ELSE DATEPART(WEEK, getdate()) - 4
END
答案 2 :(得分:0)