Good morning!
I have a query below that I need to bring inside the case only when the TarVencimento is smaller than today's date (so far I have been able to do it), but only when today's date is until the 5th day after the date of maturity. Example: A task number 11111 was due on 11/11/2017 and today is 11/22/2017 so it was not to bring this task, it was only to bring today's date from 11/11 to 15 / 11.
SELECT CASE WHEN T.TarVencimento < getdate () THEN CAST (datediff (day, TarVencimento, getdate ()) AS VARCHAR) ELSE '0' END + '(TEMPO)' FROM Task T