Leva-me de volta, mas é isso que você quer mostrar TUDO em aluguel no período, incluindo itens não devolvidos
select *
from MyTable
where on_hire < @EndDate
and (off_hire >= @StartDate or off_hire is null)
Para o acompanhamento, número total de dias para cada ferramenta
with CTE as
(
select *
from MyTable
where on_hire < @EndDate
and (off_hire >= @StartDate or off_hire is null)
)
select Tool,
sum(datediff(dd,
case
when off_hire > @EndDate then @EndDate
when off_hire is null then @EndDate
else off_hire
end,
case
when on_hire < @StartDate then @StartDate
else on_hire
end)) as DaysOnHire
from CTE
froup by Tool