I work in SQL Server 2008

```
declare @salarydates table (yearmonth int, dt1 date, dt2 date)
insert @salarydates select 202103 , '2021/03/01','2021/03/31'
insert @salarydates select 202104 , '2021/04/01','2021/04/30'
insert @salarydates select 202105 , '2021/05/01','2021/05/31'
declare @dt date set @dt = '2021/05/06'
select top 1
sd.yearmonth
from @salarydates sd
where sd.dt1 <
( select dt1
from @salarydates
where @dt between dt1 and dt2
)
order by yearmonth desc
```

When @dt is '2021/05/06' the result is 202104 --correct result

When @dt is '2021/05/31' the result is 202104 --correct result

When @dt is '2021/04/02' the result is 202103 --correct result

When @dt is '2021/06/01' no result, the result should be 202105

When @dt is '2021/12/12' no result, the result should be 202105

When @dt is '2021/02/06' no result, the result should be 202105