Я думаю, это может быть то, что вы после ...
Declare @tarif as table (
tarif_id int NOT NULL ,
start_tarif date NOT NULL,
end_tarif date NOT NULL,
day_tarif varchar(50) NOT NULL
);
INSERT INTO @tarif VALUES (1, '2019-02-01', '2019-02-10', '10'),
(2, '2019-02-11', '2019-02-20', '20'),
(3, '2019-02-21', '2019-02-28', '10'),
(4, '2019-03-01', '2019-02-10', '15');
-- Declare parameters
Declare @paramstart date, @paramend date
Set @paramstart='2019-02-05'
Set @paramend='2019-02-15'
-- Set up loop
Declare @mincount int, @maxcount int, @myval int, @curstart date, @curend date,@curtarif int, @mytarif int
Set @mincount=(Select MIN(tarif_id) from @tarif where end_tarif >= '2019-02-05' AND start_tarif <= '2019-02-15')
Set @maxcount=(Select Max(tarif_id) from @tarif where end_tarif >= '2019-02-05' AND start_tarif <= '2019-02-15')
Set @mytarif=0
-- Do loop
WHile @mincount<=@maxcount
BEGIN
Set @curstart=(Select start_tarif from @tarif where tarif_id=@mincount)
Set @curend=(Select end_tarif from @tarif where tarif_id=@mincount)
Set @curtarif=(Select cast(day_tarif as int) from @tarif where tarif_id=@mincount)
IF @paramstart between @curstart and @curend
BEGIN
Set @mytarif=@mytarif+((DATEDIFF(day,@paramstart,@curend)+1) * @curtarif)
END
IF @paramend between @curstart and @curend
BEGIN
Set @mytarif=@mytarif+((DATEDIFF(day,@curstart,@paramend)+1) * @curtarif)
END
IF @paramstart not between @curstart and @curend and @paramend not between @curstart and @curend
BEGIN
Set @mytarif=@mytarif+((DATEDIFF(day,@curstart,@curend)+1) * @curtarif)
END
Set @mincount=@mincount+1
END
Select @mytarif as tarif