如果当前日期是该月的最后 3 个工作日,则期望日期"月"应更改为"下个月"



你们能帮我在SQL Server(T-SQL(中实现以下逻辑吗?

如果当前日期是该月的最后 3 个工作日,则期望日期"月"应更改为"下个月">

例:

20180627 (Current Date) --> 201807 (Desired Date),
20180529 --> 201806,
20190226 --> 201903,
20181227 --> 201901

提前非常感谢!

使用eomonth()

select (case when getdate() >= cast(dateadd(day, -2, eomonth(getdate())) as date)
then year(dateadd(month, 1, getdate())) * 100 + month(dateadd(month, 1, getdate()))
else year(getdate()) * 100 + month(getdate())
end) as desired_month