Years ago I rewrote some liquid flow routing analysis in C# that was precisely one jillion times faster than the original code. This code was written in....a SQL stored procedure.
tl;dr Don't use SQL for recursive conditional logic.
Probably not a useful example huh?