UNION ALL with Excel file as data source - sql

I have got the following Problem.
I have several Excel files containing each the data of a country in one folder.
However I want to pull that all into one Excel report.
As the content of the source files change dayly, I guess the best way to do that is to do a import via an SQL Statement using Union All.
However the problem is that MSQuery only allows me to Access one file at a time. Is there a Workaround for that problem?
Maybe create a data model and use DAX?

This sounds like a job for Power Query, a free add-in from Microsoft for Excel 2010 and Excel 2013, and built into Excel 2016 as "Get and Transform" in the Data ribbon.
You can create individual queries to the different Excel files in the different folder, then create a query that appends all previous queries into one table, which can be loaded to the Excel data model or a worksheet table for further processing.
The queries can be refreshed with a click when the data has changed.

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.

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.

Searching SAS data sets from Excel

I am trying to find a way to search a sas7bdat file from excel for a specific value, and then copy and paste the data into an excel spreadsheet. Currently I can add the whole data set and then search it in excel, but it would be much better if I could search the data set before adding it to excel, as the data sets are sometimes too large for excel to handle.
Is there a way of doing this? Or alternatively is there a way of running some SAS code from excel that would perform the search for me?
Many thanks,
Alastair
SAS has a Microsoft Office add-in that you can use to connect to SAS datasets from excel. See their product page for more information.
There are a few other options for connecting to SAS as a data source; you can use ODBC for example. You also can do what you describe using DDE. Finally, you can produce excel spreadsheets (but not paste into particular spots, easily anyway) using PROC EXPORT or ODS EXCEL (the latter in 9.4 TS1M2+). You can filter the dataset to the appropriate size prior to exporting.

Multiple excel sheets import/export to SQL Server

I have to export SQL Serverdata to Excel and edit (make a few changes) later restore it in the data in SQL Server database itself. I have tried doing this manually but can I do this task using SSIS or some other way because I have to do this several times a day.
Googled for this all that I could find was using SSIS which has ability to export/import data of 1 sheet not multiple sheets
Thanks in advance for your answers
In SSIS, in the Excel Source component, you can simply specify the sheet name. You can have multiple Excel Components, or programmatically change the sheet name inside a loop.

Export data to Excel file using SSIS

I have SSIS Package which Exports Data from table to Excel file
Control Flow :-
Data Flow :-
This is My Step :-
Drop Excel Table
Create Excel Table with format as of my Select Query which i used to retrieve data from database
Insert Data from Database to Excel file
I Used Query Like Select * From Table Where --Some Condition
I retrieve 3000 rows out of 10000 rows and put that 3000 rows in my excel sheet.
But when open my excel sheet i saw scrollbar which goes till 10000th row and ends hence my excel sheet size also increses . how can i reduce my excel sheet size ? my excel sheet contains only 3000 rows then why blank cells which goes till 10000th row ?
SQL Server 2008 &
Visual Studio 2008 with BIDS
I believe your issue is around the method in which you are using to create the file. You have two alternatives and both should fix your issue:
Solution #1:
You can create an Excel file with those predefined columns, essentially your empty output file - this would act as your 'Template File'. Your flow would then be this:
File System Task - Copy template file to output or working directory (rename if necessary)
OLEDB Source Task - Query your source for the data (3000)
Data Conversion Task
Excel Destination Task - Put data into new Excel file
Note: You already have steps 2 thru 3 complete, you just need to make sure you are connecting to the new Excel file. Also, to clarify, step 1 is outside the Control Flow Task.
This way is helpful because you always have a blank and consistently formatted Excel file to copy and work with.
Solution #2:
The other option is to use a Script Task and create the Excel file - you could also load the data into the file in this task. This requires some basic understanding of VB.NET or C#. Basically you would need to get a XLS library (like NPOI). This is more complicated, but gives you the best functionality.
I recommend you try solution #1 and see how that works for you.
Drop table SheetName doesn't delete the sheet instead it just deletes the row . If for the 1st time you have loaded 10K rows and then again executed the package by restricting the number of rows to 3K ,the excel file will still contain those 10K empty rows as it retains the sheet along with the empty spaces .
You can use script task to delete the sheet using COM obects .But for that you need to place the Excel PIA(Primary Interop Assemply) to make it visible for VSA or else create a new excel file every time the package runs
Else as suggested by Nicarus use File System Task to delete the existing file and create a new Excel file on every execution .
Diagram :
File System Task :
Use the same components and the query for Create Table using Execute SQL task and your DFT