有人可以协助我将下面的Oracle语句转换为SQL Server吗?目标是查看日期列并确定它是否在滚动的4周内。
CASE
WHEN CC.CLIENT_ORDER_RECEIVED_DATE BETWEEN (next_day (trunc(sysdate,'DD'),'FRIDAY'))-13 AND next_day (trunc(sysdate,'DD'),'FRIDAY')-6 THEN (next_day (trunc(sysdate,'DD'),'FRIDAY')-7)
WHEN CC.CLIENT_ORDER_RECEIVED_DATE BETWEEN (next_day (trunc(sysdate,'DD'),'FRIDAY'))-20 AND next_day (trunc(sysdate,'DD'),'FRIDAY')-13 THEN (next_day (trunc(sysdate,'DD'),'FRIDAY')-14)
WHEN CC.CLIENT_ORDER_RECEIVED_DATE BETWEEN (next_day (trunc(sysdate,'DD'),'FRIDAY'))-27 AND next_day (trunc(sysdate,'DD'),'FRIDAY')-20 THEN (next_day (trunc(sysdate,'DD'),'FRIDAY')-21)
WHEN CC.CLIENT_ORDER_RECEIVED_DATE BETWEEN (next_day (trunc(sysdate,'DD'),'FRIDAY'))-34 AND next_day (trunc(sysdate,'DD'),'FRIDAY')-27 THEN (next_day (trunc(sysdate,'DD'),'FRIDAY')-28)
END AS ROLLING_4_WEEK_FLAG,
答案 0 :(得分:1)
您的oracle代码似乎计算了上周五/周六,因此您可以在SQL Server中执行类似的操作:
dateadd(week, datediff(week, 0, getdate()), 0)
由于这是基于星期一的'零'(= 1.1.1900),所以这将始终返回当周的星期一。所以要获得星期六,你只需要加上-2天,而星期五当然是-3。