VBA to send a SQL string to a Tableau Connection

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



VBA to send a SQL string to a Tableau Connection



I have an excel work book that allows users to update multiple SQL statements at once based on data entered into cells.



Then the users copy the updated SQL and go into Tableau and paste it into the corresponding custom SQL data source in tableau and refresh it.



Is there a way to send the updated SQL code directly to the corresponding connection in Tableau?





Do you want the sql sent to a twb file in Desktop or to a published working in Server or Online?
– Sam M
Aug 10 at 19:45





twb file in desktop. It becomes cumbersome to have to do this 15+ times and I'm hoping there is a way to pass the SQL.
– AlmostThere
Aug 10 at 20:12






Can you post a sample of the sql code that gets updated?
– Sam M
Aug 10 at 23:01





Select * from table A where A.ID = ‘32’ and A.date between 1/1/18 and 2/1/18...The ID can change. The dates can change. The table name can change as well.
– AlmostThere
Aug 10 at 23:41






Also the new table is unknown until it is created which means the new ID and dates are unknown as well.
– AlmostThere
Aug 10 at 23:48





1 Answer
1



If the table name is changing, that presents a challenge.



I have two suggestions.



Modify the twb xml.



A Tableau workbook file is simply an XML file. One part of the xml contains the connection information, including your custom SQL. VBA has some libraries for manipulating XML. You can write some custom VBA code to modify the XML that contains the custom SQL.



Use VBA to create/alter a view in teradata



Teradata allows database views. With VBA, you can connect to teradata and create/alter a view that changes based on your parameters from Excel. The key is to keep the view name constant, then Tableau will not need to be changed each time the underlying view definition is changed.



Of the two, my first choice would be the second option. It's cleaner and doesn't require distributing a new workbook file each time.





Option 1: I was able to open a basic TWB in notepad and edit the XML. However, I tried a more complex/robust Tableau and I couldn't even open it up in Notepad. I was planning on opening it in notepad via Excel, then find and replace the updates needed, and then paste it back into the TWB file that was opened via excel and save it. Option 2: that would work and does seem like the easier to maintain solution, however, I would still need the ability to query the data from time to time, and since the view would get updated/overwritten I wouldn't be able to do that.
– AlmostThere
Aug 13 at 16:04







By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard