SQL Export to multiple Excel Worksheets - sql

everyone!
I'm mostly just curious if this can be done, but here we go:
I have a query I run about once a month that ends up going into an Excel Worksheet. It creates a list of businesses and representatives. Now, I know that you can create SQL code that exports query results directly to a worksheet (see Export SQL query data to Excel), but I want to know if I can take the result, and export it using SQL to multiple worksheets based on representative? So that each rep gets a worksheet of just their businesses?
I'm thinking it would involve some kind of loop (see SQL Server FOR EACH Loop), but I just can't find anything definitive.
Thoughts?
Thanks!

You can create an SSIS package to achieve that. Write a different query for each rep and export the results into an Excel.

Related

Fetching Query Result Directly Into an Excel Cells

I am currently using Oracle Apex to write queries and copy and paste the results into an Excel file. I have also used mySQL Workbench in the past.
My question is it possible to link a database to Excel and produce the results? For example in cell A1 I would want to type "select sum(sales) from accounts" and when I click enter, the result would appear in that cell after fetching the query?
I may be over thinking it or expecting something that is not possible. Any help is appreciated
You can connect your excel with a database and pull the data to the sheet, but writing queries in an individual column still need to figure out. In between, you can take a look at the ODBC configuration to connect excel with the database, Hope this will give some insights.
https://www.devart.com/odbc/mysql/docs/excel.htm

Join (INNER JOIN) local Excel table in Oracle SQL Query - VBA

I'm having trouble performing a query on a remote Oracle SQL Server via Excel VBA while trying to perform an INNER JOIN in the same query with a local table in a Excel file sheet.
Example:
Excel Sheet with local table ["LTE_Cells$LTE_Cells_Tmp"]:
Sheet "LTE_Cells"
Oracle SQL Query
SELECT a.STARTDATE, a.ENODEB, a.EUTRANCELLFDD, (a.COUNTER_1/8/1024)+
a.COUNTER2/8/1024) AS Total_Total_Traffic_TB FROM »»»LOCAL_EXCEL_TABLE««««
INNER JOIN REMOTE_DATABASE.LTE_KPI_1 a ON
((»»»LOCAL_EXCEL_TABLE««««.EUTRANCELLFDD =
REMOTE_DATABASE.LTE_KPI_1.EUTRANCELLFDD) AND
(»»»LOCAL_EXCEL_TABLE««««.ENODEB = REMOTE_DATABASE.LTE_KPI_1.ENODEB)) WHERE
(((REMOTE_DATABASE.LTE_KPI_1.STARTDATE)>=sysdate-3));`
Thanks in advance for the help!
This doesn't answer your question directly, and I may be all wet on this but I don't know that either Excel or Oracle explicitly handles what you are trying to accomplish.
However, MS Access will out of the box. Short answer: I think you are using the wrong tool for this task. You are using the proverbial hammer to saw a board in half. Link the spreadsheet and the Oracle table as linked objects in Excel, and your query should be easy-peazy.
Longer answer: while Access does this simply and easily, it can and probably will leave a path of destruction behind it on the DBMS. Specifically, you can expect to thrash the shared pool in Oracle, as Access will be issuing one query (using literals, no less) for every line in Excel. For 1,000 lines, it probably doesn't matter that much, but if you're going to do this on really large datasets, you will make a fast enemy out of your DBA.
Extended answer: really, the best way to do this is to load the contents of those Excel spreadsheets in Oracle tables and let the DBMS do the heavy lifting. This is bread and butter for the RDBMS.

Save Results of a SQL Query to an Excel File

I have an SQL Query I'm using to Pull Beds by Unit and the related Number of Beds in Use and Available.
What is the SQL Syntax to have the results of the query save to an excel file (existing or new).
Please Note: I have been searching and I can't believe this isn't easy to figure out. Lots of people seems to use other tools but I want to do it in SQL Stored Procedure - Is this possible?
Thanks so much for your help!
The easier way to do this is from Excel, utilize a connection to your SQLDB and then pull the data into excel, that is the most efficient way to do it.

SQL Server 2012 to Excel 2010 Copy and Paste

I am trying to copy and paste from SQL Server 2012 to Excel 2010.
My query has the 13th column that is delimiting that is ruining the results.
It has a long description field that gets cut off after a space or a certain amount of characters.
It doesn't matter how big or small my order might be or how dumb my questions are, I get great service quickly. My account manager constantly comes through for me, and is the reason all of my purchasing inquiries start with blah
Please help.
I have tried the following methods
Tried saving without any delimiting to the Excel FIle
Changing the Query Results to add Quote Strings contianing list separators when saving .csv or copying result.
Your problem is that you have already used TextToColumn in this instance of Excel. Close Excel. Restart Excel. Execute the query in (I assume you mean) Sql Server Management Studio (AKA SSMS). Left-Click the square in the top left of the results to select all the rows in the query results windows. Then Right-click and select Copy With Headers. Then go back to Excel, select cell A1 and paste. The headers should take care of the column splitting.
Hth,
Ojf
Check if you are able to Export data using DTS Import Export Wizard of SQL SERVER 2012.
Try saving in both Excel(.xls) and Comma Separted file(.csv).

SSMS: query export to Excel

I am trying to export 260+ column query to Excel from SSMS 2005.
When I finish up the wizard, I get the "Too many fields defined" error.
Is there any way of getting around this?
I suppose I can run that query via New Query and copy and paste to Excel but it doesn't copy over the column names.
Thanks
This seems to be a problem of your version of Excel other than SQL Server. If you have Excel 2003 (or an older version), then you only have 256 columns, so you won't be able to "get around this". For Excel 2007+, you shouldn't have a problem at all. By the way, you can still select all records after you run your query, right-click in the results, and select "copy with headers" to get the column names.