Your TD code does not look like valid code. Can you run that code on your TD server using Teradata SQL assistant?
IN general an SQL query should be of the form
select ....
from ...
where ...
group by ....
having ....
order by ....
Where just the SELECT and FROM clauses are required.
... View more