VBA to send a SQL string to a Tableau Connection - sql

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?

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.

Related

Excel spreadsheet as parameter for report

Has anyone created a report that could use an Excel spreadsheet attached by the user as a parameter for the report? An example would be a list of potential customers in Excel, and whether they exist or don't exist in the database.
I know something like this is easier to accomplish with a manual SSMS query. However, we have several query requests similar to this which are common requests.
Basically want the user to attach their spreadsheet and compare it with data in the database and then spit out a comparison report.
Use SSIS job to load data from spreadsheet to database and then compare data in usual way with queries.

Extract Data from SQL to Excel without overwriting the previous Data

I was able to use SQL Server Agent to create a job that extract Data from SQL Server 2008 to Excel Format Daily. However, is there anyway to create a job that keep all the extracts separately without overwrite the previous files? I would really much appreciated your help.
Thank you.
When using OLE DB/Jet data provider for Excel, there is a way to specify the target worksheet name. A worksheet in Excel is a rough equivalent of a database table. One option is to use a different worksheet name each time (say, based on a current date). Another option would be to append the data to the existing worksheet, if that's what you're after. If SQL Server Agent job does not allow you to do something like that, then you may want to create a small app instead.
While Copying from OLEDB to Excel, You can dynamically pass the file name through the expressions based on the Datetime.
Ex: Filepath+Date1_mmddyy_hhmmss
Every time the file generates, It will create a file with new file name and Excel file should be passed as an expression.

How to connect an Excel file to an Access Database

I have created a query in an Access database and exported the query result into an Excel file. Now, I want to connect that Excel file to the Access database (or to that query) so that whenever some fields are updated in database, those changes would be automatically updated in the exported Excel file (report). What would be the best way to do it?
Thanks
You can create a link between Excel and an Access table or query by going to the Data tab on Excel and clicking the "From Access" icon.
Alternatively if there is a trigger inside access that you can use to update data (or if you don't need real time updates just hourly or daily ones), you could have access programmatically re-export.
If you want to work with data in Access, but still maintain the data in Excel, you need to link to the data rather than import it. Follow these steps:
Create a blank database or open an existing file in Access.
Select File, Get External Data, Link Tables.
Select Microsoft Excel as the file type.
Select a worksheet or named range to import, and then
click Next. You can import only one worksheet or named range at a
time, and each one will become an Access table.
In the next dialog box, select or deselect the check box First Row
Contains Column Headings, depending on whether your worksheet has
headings. Then click Next.
Enter a name for the table (or accept the default name that Access
suggests), click Finish, and click OK.
Now you have an Access table that looks almost exactly like the imported table. The advantage is that it maintains a live link to the Excel worksheet and can be edited in either application.

Saving results of a SQL Server stored procedure to an Excel format programatically

I need to save the results of a SQL Server stored procedure into an Excel file.
How can I do this programatically, as part of the same stored procedure - preferably as the last step of the stored procedure?
Please note that I do not have a separate web application. I want to perform this save functionality to Excel, as part of the stored procedure itself.
This is a bit long for a comment.
My first suggestion is to save the data as a delimited file, which can easily be imported into Excel. This should be fine for archival purposes, for instance, or for sending the results around by email.
The next suggestion is to save the results in a table, and to have a data connection to that table. You can then have a query in the Excel file that automatically refreshes the data. This is handy for having special formatting and charts in the Excel file.
Another option is to use openrowset() to directly write to an Excel file. The process would often be something like copying a template file to a new location and then writing the data to it.
The best method really depends on what you want to do with the results.

SSIS - using VB to dynamically create ole db source where the SQL source is too dynamic

I'm very new to SSIS, but have this week been completely burried in turorials of how to use it, this has been very fruitful so far but now I'm stuck with what seems a more complicated task.
I have two source SQl tables, which are dynamically created using the TSQL pivot function - so the numebr of columns in each will vary.
I feed a list of criteria into a for each loop whic his set to use an ADO enumerator to go through this data set and has a script task to set the string variable SQL_DOWNLOAD_STRING to point to one of the two poential tables using an IF statement. TABLEA or TABLEB.
I tried using the standard OLE DB source in the data flow, but the associated meta data was generated based on TABLEA at the time of build. I then set the SQL statement to be based on the variable SQL_DOWNLOAD_STRING and when I execute, the meta data of the source has changed as obviously it is a differnt table. That said even if itwas the same table there is no guarentee that the columns would be the same.
So my question is - how do I create the OLE DB Source dynamically so that it reconfigures to the new structure of the table?
Then I'm trying to export the data to an Excel workbook (which again I can do for a static source) but in this instance the mapping would need to change too & I imagine I'll need to rebuild the destination table to match the source from above.
If I can get a working example - then finishing the project should be pretty staright forward from there - examples for this sort of thing seem pretty limited though :(
Please help! (PS I'm working in VB)
Thanks