你们能帮助我在SQL Server(T-SQL)中实现以下逻辑
如果当前日期属于该月的最后3个工作日,则所需日期'月份'应该改为'下个月'
示例:
20180627 (Current Date) --> 201807 (Desired Date),
20180529 --> 201806,
20190226 --> 201903,
20181227 --> 201901
非常感谢你!
答案 0 :(得分:0)
使用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