Pseudo-code
As some comments still wait for answers, and as I have no Teradata to test on, here is some pseudo-SQL that focuses on the interesting part of determining until when the SLA will run over week ends and holidays:
-- Use recursion to walk through all days until our SLA reaches 0 after having been decremented on each working day.
-- An alternative would be to use window functions to mark each day of the theorical SLA period as working or non working (which would expand the actual SLA). /!\ This would require that we explore more than the initial SLA, for example 2 * SLA + 7 days, so that if the theorical SLA ended on a Satursday, we have also seen the Sunday (week end, so expands SLA), and possibly the holy Monday (expands SLA), until reaching the next working Tuesday.
with recursive
r as
(
select d, sla, d cur, sla remain from req
union all
select
d, sla,
cur + 1,
remain -
case
when extract(dow from cur + 1) in (0, 6) then 0
when exists(select 1 from holiday h where h.d = cur + 1) then 0
else 1
end
from r
where remain > 0
)
select * from r where remain = 0;
| d |
sla |
cur |
remain |
comment |
| 2025-05-23 |
4 |
2025-05-30 |
0 |
23 was a friday, 24 and 25 on week end, 26 is a holiday; so SLA runs on 23, 27, 28 and 29: due date is the 30th |
| 2024-12-20 |
15 |
2025-01-14 |
0 |
Christmas + New Year + 4 week ends + 15 days SLA = 25 days later |
… Well OK in fact this pseudo-SQL works on PostgreSQL.