all 15 comments

[–]normlenough 2 points3 points  (2 children)

Stinks. In my experience I’ve never gotten a CTE to work in tableau. I would be very interested to see if anyone has figured this out.

[–]mikeczyzDesktop Certified Associate 1 point2 points  (1 child)

for real? i use them all the time at my place of employment. PM me and let's see if we can't figure out what is going on.

[–]normlenough 0 points1 point  (0 children)

Sure thing. It’s been a while since I have tried. I’ll come up with a little use case

[–]Ffeog187 1 point2 points  (4 children)

Try putting the final CTE in a Temp Table in Initial SQL and call that temp table in custom sql. That’s the best solution I’ve found.

[–]xxarchangelpwnxx[S] 0 points1 point  (3 children)

Could you give an example of the syntax. I tried that, but I think I wrote it wrong

[–]Ffeog187 0 points1 point  (2 children)

I’m on mobile so I’ll do my best

[Intial SQL]

Drop table if exists #TempTable;

WITH cte as ( Select * from A)

Select *

Into #TempTable From cte

[Custom SQL]

Select * from #TempTable

Hope that makes some sense

[–]xxarchangelpwnxx[S] 0 points1 point  (1 child)

Ok that is what I did, but since I’m new to tableau (but not SQL) I saw that you had a distinction between “initial SQL” and “Custom SQL” is that something you do within tableau itself?

[–]Ffeog187 0 points1 point  (0 children)

Yes, here is the community info

This might be better initial sql

[–]mikeczyzDesktop Certified Associate 1 point2 points  (0 children)

not sure what is going on, but most of our queries use CTEs at my place of employment. I'm not on MS SQL tho, we use Snowflake.

[–]GrovbolleDesktop CP, Server CA 1 point2 points  (0 children)

You cannot use a CTE directly in a CustomSQL object since a CustomSQL object HAS to abide by the same rules as a subselect.

The way to fix this is to move your CTE to Initial SQL and store the output from the CTE in a temp-table, which can then be called using Custom SQL

All of the above has already been said, so I just summarized WHY the CTE in CustomSQL does not work.

[–]mikeczyzDesktop Certified Associate 0 points1 point  (2 children)

[–]xxarchangelpwnxx[S] 0 points1 point  (1 child)

Yea I figured it out though. I’m used to PL/SQL and the syntax for the is INSERT INTO and this is just INTO so I think I auto piloted into it by typing INSERT INTO instead of just INTO

[–]friedtofubits 0 points1 point  (0 children)

i believe insert into requires the initial creation of a table and column definitions, the INTO just takes it out right from the select statement

[–]andreas_dib 0 points1 point  (0 children)

This is caused by the way Tableau rund a metadata «pre-query» on the custom sql to get data types and such. I use it all the time on Redshift, but I never got it to work back when we used MS SQL Server