Hi, thank you for this very nice procedure :)
I think there may be a slight problem with datetimes (else I misconfigured something).
I was running the procedure as a SQL job, and it started failing with:
"Warning: Null value is eliminated by an aggregate or other SET operation. [SQLSTATE 01003] (Message 8153) The datediff function resulted in an overflow. The number of dateparts separating two date/time instances is too large. Try to use datediff with a less precise datepart. [SQLSTATE 22003] (Error 535). The step failed."
during the evening (24H clock). As the time passed 0:00 it ran flawlessly again. I am sad to say that I do not have the correct time for when it started failing, but I believe it was around 21:30 I had the last entry (before truncating the logging table (yes I know...stupid).
Is this something you have seen before? Did I configure something wrong?