-1

In Tableau, I'm trying to add a column through Alter Table in a custom SQL It looks like this:

 ALTER TABLE (SELECT [W$].[W], [W$].[SDate], [W$].[EDate], [Date E$].[Date] 
 FROM [W$],[Date E$] 
 WHERE [Date E$].[Date] 
 BETWEEN [W$].[SDate] AND [W$].[EDate]) 
 ADD [Type] string NOT NULL DEFAULT "P1"

But I get an error saying Syntax Error in FROM clause.

I also get this error if I use ALTER TABLE [Date E$]

 ALTER TABLE [Date E$] 
 ADD [Type] string NOT NULL DEFAULT "P1"

error message:

Database error 0x80040E14: Syntax error in FROM clause.
; The query: SELECT TOP 1 * FROM ( ALTER TABLE [Date E$] 
 ADD [Type] string NOT NULL DEFAULT "P1" ) [TableauSQL]

This is my first time using Alter Table so I'm not sure where the FROM clause is being used, or if I'm doing this incorrectly. I'm following the instructions I found here: Add a column with a default value to an existing table in SQL Server

Is it possible that Tableau doesn't allow Alter Table to be used when creating a Custom SQL?

I am using Tableau Desktop 2018.1.2

Jummi
  • 123
  • 1
  • 13
  • First, your first alter table statement makes absolutely no sense. You apply alter statements to tables, not queries. Second, why do you want your reporting tool to alter the table structure? I'm hard pressed to think of a use case. – Sam M Oct 07 '18 at 07:15
  • It's my first time using Alter Table so I wasn't sure if I was using it correctly or not - thus the question. I want to alter the table by adding a column so I can create a variable to join with another data source in Tableau. – Jummi Oct 09 '18 at 14:56

1 Answers1

3

Tableau custom SQL will not allow DDL statements such as Alter table. It creates a read-only connection to the database. You might be able to do this using the initial sql function that is available when you setup your connection. Really Tableau is the wrong tool for this. If you want to alter tables you should use a SQL client thats appropriate for your database.

Nate
  • 200
  • 5
  • Thanks for the explanation. Unfortunately it doesn't look like initial sql isn't available for my data source type (excel) – Jummi Oct 09 '18 at 14:55