KNOWLEDGE BASE

How to Switch Table in Custom SQL Using Parameter


Published: 23 Dec 2022
Last Modified Date: 25 Dec 2022

Question

How to Select Table in Custom SQL using Parameter.
For example, there are tables like [table_YYYYMMDD] in the database and it will generate a new one every day. How to select today's table in Custom SQL.

Currently, Tableau does not support using parameters as table names in Custom SQL.
"Parameters can only replace literal values. They cannot replace expressions or identifiers such as table names."

Environment

  • Tableau Desktop
  • Custom SQL

Answer

The ability to set a parameter as a table name is not currently built into Tableau Desktop.
Following is a possible workaround.

Instead of using the parameter to select the table you want in Custom SQL, just query all the related tables that you want to select with a parameter using a wildcard table query and add a data source filter in Tableau Desktop to select the one table you want.
The steps are as follows.

1. Query multiple tables using a wildcard table. 
e.g. Bigquery: FROM `bigquery-public-data.noaa_gsod.gsod*`
e.g. SQL Server: select * from [Schema] where name like '%table%'

2. Add a data source filter to specify the table you want. 
Filter Data from Data Sources

To voice your support for the inclusion of this enhancement in a future product release, add your vote to the following Community Idea:
Select Table in Custom SQL using parameter
 
Did this article resolve the issue?