我正在寻找一个SQL解决方案,以在Oracle Developer SQL的工作,将计算当前季度的开始和结束日期基于sysdate和财政日历开始于2020年2月1日。每个季度是固定的13周(91天) --而不是3个月,因此每年的会计日历略有不同。
代码将上载到自动报告,并且不希望每年都进行调整。本年度会计日历作为示例说明附后。Current Fiscal Calendar
我开始沿着这条路走,但当我意识到开始日期不能以这种格式正确时,我迷路了。
End解决方案将用于where子句以确定报告日期范围,例如( Where Report_Date between Modified_Quarter_Start and sysdate )
select trunc(add_months(add_months(trunc(sysdate,'Y') -1 ,
to_number(to_char(sysdate,'Q')) * 3),-1),'MM')
start_date,trunc(add_months(add_months(trunc(sysdate,'Y') -1 ,
to_number(to_char(sysdate,'Q')) * 3),+2),'MM')-1 Endd_date,
add_months(trunc(sysdate,'Y') -1 ,to_number(to_char(sysdate,'Q')) * 3) end_date ,
to_char(sysdate,'YYYY - q') qtr from dual非常感谢您的帮助。
发布于 2020-05-20 01:10:58
发布,以防其他人在未来遇到同样的预测。在阅读了另一个线程中提到的用于固定日期的case语句后,我想到了这个解决方案。
Select Trunc(sysdate - to_date('02-Feb-2019')),
Case When Trunc(sysdate - to_date('02-Feb-2019')) > 91 Then to_date('02-Feb-2019') +
Round( to_number(Trunc(sysdate - to_date('02-Feb-2019'))/91),0) * 91
Else null End Current_Quarter_Start,
Case When Trunc(sysdate - to_date('02-Feb-2019')) > 91 Then to_date('02-Feb-2019') +
( (Round( to_number(Trunc(sysdate - to_date('02-Feb-2019'))/91),0) +1 )* 91)-1 Else null End Current_Quarter_End From Dual https://stackoverflow.com/questions/61895952
复制相似问题