1 Reply Latest reply on Dec 6, 2018 10:17 AM by Vinnie Ahuja

    Dynamic Teradata table name in Custom SQL

    Lawrence Chan

      I have tried using a parameter in my custom SQL to have it switch between tables with identical columns. While the parameter works in a WHERE clause, I am not able to do this for table. For example, the SQL statement I used is:

       

      SELECT * FROM DATABASE.<Table Parameter>

       

      The table parameter is a string variable, and the following error shows up:

      [Teradata][ODBC Teradata Driver][Teradata Database](-3707)Syntax error, expected something like an 'UDFCALLNAME' keyword between '.' and the string 'TableName'.

       

      I have searched over the web, but haven't had any success. Any help would be greatly appreciated.

        • 1. Re: Dynamic Teradata table name in Custom SQL
          Vinnie Ahuja

          Hi Lawrence -

           

          I think what you have going on is that, because you are sending the parameter to Teradata as a string, it is putting it in single quotes.  This is why it works in a WHERE clause but not in the table name.  So essentially you are sending it this....

           

          SELECT * FROM DATABASE.'myTableName'

           

          I am not sure there are any string manipulation, escape characters, or type casting SQL functions that will remove the single quotes, but that would be the direction to explore (I am not aware of any).

           

          Depending on what you're specifically looking to accomplish and how many tables you're thinking about having as choices, there may be other approaches.  If the number is small you may be able to create a data source for each of the tables and handle from within Tableau.

           

          HTH

          Vinnie