I am using Teradata version 14.00.07.12 . Checking for nulls in left join does not seem to be working. When I create the following:
Putting filter conditions on the inner table (e.g. "And tbl2.TableName = cte.Table2 And tbl2.DatabaseName = cte.DB" in the first subquery) into the WHERE clause effectively makes it an INNER join. These should be in the ON clause instead.
You could also modify the WHERE clause to allow for NULLs in these other columns for nonmatching rows, but the resulting plan might be less efficient.
This is not a Teradata-specific issue, SQL Server will return exactly the same result, as it's based on Standard SQL :)
You'll find a nice case study on the where-to-place-conditions topic in the manuals: