问题
I am connecting Tableau with SQL Server and I am trying to use the T-SQL query. I just want to know, does Tableau support CTE (Common Table Expression)?
I came across this article and it said CTE is possible: http://kb.tableau.com/articles/howto/using-common-table-expressions
Here's my query:
WITH Test (Store) AS
(
SELECT
Store
FROM
FiscalReporting.dbo.LBR_STR_ORG
)
SELECT
Store
FROM
Test
When I am running this query, I get an error message. Please let me know if I am doing something wrong.
Most of my SQL queries are built with CTE. So it would be greatly appreciated if I get any help. Also, I am new to Tableau.
Thanks!
回答1:
Tableau does not support CTE expressions in "Custom SQL". But it does in "Initial SQL".
Here are two examples, how to use it:
https://kb.tableau.com/articles/howto/using-common-table-expressions
https://dabblingwithdata.wordpress.com/2016/12/10/actually-you-can-use-variables-ctes-and-other-fancy-sql-with-tableau-after-all/
The solution involves using "Initial SQL" where you can create temp table (the one with # at the beggining - SQL Server) and then you refer to this temp table in your "Custom SQL"
来源:https://stackoverflow.com/questions/42570138/tableau-common-table-expression-cte-sql-server