user9809879
user9809879

Reputation:

How to write dynamic sql query in Tableau?

I've to create a tableau dashboard using 2 different database tables, one database table has static table name and another database has dynamic table name which changes every week.

Example of dynamic table:

SELECT * from abc123;

Now this abc123 table in next week could be abc111, I am getting table name using API.

Can I create such dashboard using data blending method?

I don't want to do ETL for this.

Upvotes: 3

Views: 3623

Answers (1)

Shriram R S
Shriram R S

Reputation: 136

Yes, you can pass the table name as 'parameter' while connecting SQL. But an impediment, when you pass table name in parameter.Tableau will automatically add single quote before table name while querying. For example if you enter table name as abc123 it will pass as 'abc123' to database.So you need to add single quote to tables in database before following below steps

  1. Connect to SQl Server
  2. Click on 'New Custom SQL'
  3. Click 'Create New Parameter' enter image description here

    1. Configure Parameter like below enter image description here

5.Add the 'Dynamic Table Name' to custom query editor enter image description here

6.Click 'Ok' to complete.

Once you done with above steps, you can change the table name from 'parameter' pane in Tableau. Also, you can add this parameter to dashboard and change the value directly from there

Upvotes: 3

Related Questions