Tableau - Common Table Expression (CTE) SQL Server

不想你离开。 提交于 2020-06-17 02:00:57

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!