解题过程:
declare @first date = convert(date,dateadd(DAY,-day(getdate())+1,getdate()),23)
declare @second date = convert(date,dateadd(DAY,-day(getdate())+2,getdate()),23)
declare @end date=eomonth(getdate())
if DAY(GETDATE())%2=0
begin
while @second<=@end
begin
print @second
set @second=DATEADD(DD,2,@second)
end
end
else
begin
while @first<=@end
begin
print @first
set @first=dateadd(DD,2,@first)
end
end
结果:
2023-09-02
2023-09-04
2023-09-06
2023-09-08
2023-09-10
2023-09-12
2023-09-14
2023-09-16
2023-09-18
2023-09-20
2023-09-22
2023-09-24
2023-09-26
2023-09-28
2023-09-30
想再优化一下