select 32-Day(getdate()-Day(getdate())+32)
流程:
設當前時間 : 2021-10-28
1.當前時間 - 當前時間的天數 = 上月末
select getdate() - Day(getdate()) -> 2021-10-28 - 28 = 2021-10-0 -> 2021-9-30
2.上月末 + (大於一個月小於兩個月的天數) 33 = 當前月末 + 多出來的天數
select getdate() - Day(getdate())+33 -> 2021-9-30 + 33 = 2021-11-02 -> 2021-11-0 + 2天 -> 2021-10-31 + 2天
3. 33 - 多出來的天數 = 當前月末的天數
select 33 - Day(getdate()-Day(getdate())+32) -> 33 - 2 = 31天