I have a validation tool that needs to be run ~300 times for various inputs. I'm planning to use a cursor to loop through all the required inputs (as the validation query is created dynamically)
I've been asked to export all this information to an excel file (separated into unique sheets for each of the ~300 resulsets.).
From what I've read about SSIS, it isn't able to export dynamically created queries into an excel file (if I'm mistaken, please correct me!).
I've also tried using dbo.sp_OACreate, but the security settings on the server I'm using disallow me from doing so.
Is there another way to export my ~300 resultsets into an excel spreadsheet programmatically?
It would seem that there is no way to do this using sql server 2012. I ended up using a CLR program to query and export the data to an excel spreadsheet.
I used datasets to run my queries and the Microsoft.Office.Interop.Excel library to export it to a spreadsheet.
Related
I currently have a package that creates an excel spreadsheet with multiple tabs, and it names each column in each tab. Later in the package, I have excel connections that select my data using queries and populates each column in each tab based on the mappings I define. This has worked for a long time, but since a driver update, my OLE DB connections wont let me create the excel spreadsheet anymore. The key here is that the package needs to be able to be called by a scheduling system and be totally hands off and self sufficient. Also, the excel spreadsheet is created brand new with every execution of the package so we can keep an archive of old reports.
I've tried to use the existing excel connections to also build the spreadsheet, but I don't see a way to populate multiple tabs in the same spreadsheet with excel connections.
Is there a better way to do this without having to do a C# script.
I would like to know if there is any VBA code which allows me to execute .sql files by clicking a button in Excel?
I've been surfing different webs, but all of them showed code which consists into write the SQL query in the macro, despite it isn't what I wanted. So I have stored .sql scripts as files in different folders on my computer and what I want is to run this script by clicking a button in Excel using VBA.
Short answer is no. There is no magic button in Excel that does that. Easiest that I can think of is run/import that .sql to MySQL, SQL Server, Postgres, etc. to become a database. Example using MS SQL Server:
How do I import a .sql data file into SQL Server?
Once you run successfully that .sql into a DBMS, you may use built-in tools of that DBMS to export the tables into Excel. See the link below as an example:
How to Import and Export SQL Server data to an Excel file
It may not be as easy as pressing a button but not as tedious as hardcoding it. I hope it helps.
I'd like to import some .txt tables to PowerPivot without clicking "From Other Sources" --> "Text File", but rather by running a VBA macro.
The idea is that there are several .txt tables, say
C:\Table1.txt
C:\Table2.txt
C:\Table3.txt
etc.
and to create a user form or similar so that a user can select which tables he needs, then VBA creates a single appended table in PowerPivot of the ones selected. I'd know how to do that if not for two parts:
1) How to import a table to PowerPivot from an external source (C:\) using a VBA command?
2) How to "append" those tables into one through VBA such that they wouldn't appear as different tables in PowerPivot, but rather as one table with always the same name?
I can find tangent questions and information, but no working examples of how to automate importing tables from external .txt sources (or .csv or .accdb for that matter) into a single PowerPivot table like this...
Thank you very much!
Power Query allows a GUI driven interface to do exactly what you want without VBA. You may want to consider that took instead, as it interfaces natively with Power Pivot and can be embedded in a hosted workbook, whereas the VBA solution could never work on SharePoint or Power BI.
I have an .mdb file, which is used as a data storage by one particular application. The application itself does not have tools to insert large amounts of data, and I need to insert around 300-400 generated records.
How can this be accomplished without using VB? (since I know nothing about it)
At first I thought that writing a procedure, but from what I can tell Access does not support procedures and functions (which ir really weird), only basic SQL statements.
Is exporting data into other DB like Postgre, writing and running a procedure there, and importing the data back into .mdb file possible? Or there are other solutions?
If you're looking to export data from a specific table then select that table and right click on it. A menu will appear that allows you to export the contents of that specific table. Choose the format (probably .csv or .txt for max flexibility) and then import it whereever and manipulate it accordingly.
If you want to reimport your results then choose from the File -> Get External Data -> Import menu and import your newly manipulated data. That should do it. Just make sure that the data columns align properly with the table your importing into. This shouldn't require any VBA. This advice is pertinent to Access 2003.
I am storing data in a backend database (PostgreSQL) which is running on a Linux machine. I want to be able to fetch data from the database, and populate a sheet in an excel workbook, so that I can carry out analysis in Excel.
It has been quite a while since I wrote anything in VBA, so I would appreciate some help (or links) in getting started. I would like to know the best way to approach this:
Pure VBA solution OR
Mixture of C# or other .Net language for data extraction logic and VBA for manipulating Excel objects (sheet data population etc)
Any ideas, tips, snippets and/or links that can help me get started on the twin objectives:
fetching data from a backend database (PostgreSQL) into Excel
populating a specified sheet in Excel with the columnar data retreived from the database
will be much appreciated.
If you are just trying to import data, Excel can do that without additional code. Just set up your windows client to connect to your postgreSQL server thru ODBC. (Here's one way guide to setting that part up: enter link description here
Then in Excel (Use a modern version, like 2007 or greater) from the "Data" tab, click on "Existing Connections" to connect to the ODBC connection you set up and pick the tables/data to import into excel. Once the spreadsheet has loaded the data, you can just click the "Refresh All" button to update the data.