2 666
create table #t
(
dt date not null,
ss int not null,
primary key(dt)
)
insert #t(dt,ss)
values
('2021/01/01', 1)
,('2021/01/02', 2)
,('2021/01/03', 3)
,('2021/02/01', 10)
,('2021/02/11', 11)
,('2021/02/12', 12)
,('2021/03/01', 20)
,('2021/04/01', 30)
declare @mydayte date = '2021/01/02';
select
ss
from
(
select
dt as dtS
,ISNULL(DATEADD(DD,-1, LEAD(dt) OVER (ORDER BY dt)),'9999/12/31') as dtE
,ss
from #t
) as intervals
where
@mydayte between dtS and dtE
29 abr 2021, 03:21

