I need to export data from all the tables in a schema on SQL Server to different Excel files. I only have two software to access the database:
SQL Server Management Studio
DbVisualizer 6.5
I think latest pro versions of DbV have the option of exporting into xls. How can I do without these?
Please help.
You can use Bcp utility to export your tables.
One table sample in the answer of this question (see Using BCP (Command Prompt)):
Export table from database to csv file
You should format this bcp command in a stored procedure:
Get the list of your tables
For each table, export with bcp
See integration of bcp inside a stored proc here: http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=49926
I find the easiest way is within SQL Management Studio type the select statement
select * from table. Then select the left upper section of the results grid when all rows are highlighted right click on and select copy with headers. Then paste to excel. I do it all the time. Beware datetime columns as they need to be formated in excel.
Related
i have next query
select no,
item
from myTable
and I get next table
no item
1 a
2 b
3 c
4 d
I use tsql, Microsoft SQL Server Management Studio.
Is there any way to write here some code to export table from my select in excel...
I am not aware of any way to write a query in SSMS and then export the results to excel, but you can connect an excel sheet to SQL Server and run queries into an data table from there using the From Other Sources - From SQL Server menu in the Data tab on the ribbon:
This is good if you want to build on that data within Excel and you need to refresh the data but don't want to update your formulas. There are obviously security implications with this as users of the Worksheet may be able to access other data on your server.
If you want to simply export an Excel file with data in to a file store, you would need to use SSRS and a report subscription. Alternatively, if you simply want to save the results of your query to a file, you can either copy and paste manually or choose to Save Your Results To Text in SSMS:
from your excel sheet you can create a dynamic connection between a SQL Server database and your Excel workbook.
Follow the steps in below link.
Steps to Connect a SQL Server database to your workbook
I have an Excel spreadsheet with several rows I would like to store that data in a SQL Server table right from Excel. I mean, I would like to press a bottom in Excel (not in SQL Server) to store this table in my SQL Server database.
I have been googling but every solution I find is using SQL Server Export/Import wizard. Is there any way to do this right from Excel?
Thank you! I appreciate any help
Yes there is but it will require some development on your side. For example you can create VBA macro like the one shown in this article
Export Import Excel SQL
You could create SSIS package, but this requires running it outside of the Excel or otherwise another macro will be needed to call the SSIS jobs,
You could use PowerShell and OpenXML if the Excel documents are xlsx only.
Hope this helps
We have an excel file more than 500 columns. And we have to import this file into MS SQL SERVER 2008 table. But it only accepts 255 columns.
Can anyone suggest a way to import/copy excel data to sql table ?
please go through below link and follow the steps
https://www.mssqltips.com/sqlservertutorial/203/simple-way-to-import-data-into-sql-server/
While using the Import wizard, Click on Edit Mappings on the "Select Source Tables and Views" page of the wizard, check the Type, Nullable, and Size columns for each source column. And must and should mapping should be done properly
Did you try bulk Insertion?
You can able to move excel data into SQL Server using bulk insert command below.
BULK INSERT table_name FROM 'C:\Directory\excelfile.csv' WITH (FIELDTERMINATOR='\t',ROWTERMINATOR='\n', ROWS_PER_BATCH=10000)
I want to export data from a query to excel file. I know that there is a lot of questions like these one here, but no one is acceptable in my situation.
For example, like this topic using OPENROWSET: T-SQL: Export to new Excel file
insert into OPENROWSET('Microsoft.Jet.OLEDB.4.0',
'Excel 8.0;Database=D:\testing.xls;',
'SELECT * FROM [SheetName$]') select * from SQLServerTable
It only execute successfully when I create testing.xls myself, and also define exactly number of columns that will be export from my query in this excel file. Otherwise, an error occur: Column name or number of supplied values does not match table definition.
I also try another solution here: http://weblogs.sqlteam.com/mladenp/archive/2006/07/25/10771.aspx using Exec master..xp_cmdshell
It is really work, but, I heard that xp_cmdshell is a big security threat for SQL Server. So, may be I shouldn't use it.
Is there any other way I can try?
If you're looking for a quick and dirty solution, you can use Management Studio itself.
Here are the steps:
write your query and run it
right click the Results pane and select "Save Results As..."
select your folder/filename and ensure CSV type is selected below
now open your CSV file using Excel; if appropriate save it in Excel as a native Excel format
That won't help you if you need programmatic solution, in which case you have to use Microsoft (Microsoft.Office.Interop.Excel) or 3rd party solutions; you can even build one using Office Open XML.
If you need TSQL solution, OPENROWSET which you are mentioning in the question should be fine.
You can use Excel-only solution and import data using Data pane in the Excel itself (Import from SQL server).
Another possibility taht doesn't have to be coupled to SQL Server or Excel itself is Powershell. However, I'm not into Powershell so if you prefer this method you will have to investigate a bit more.
Also, this is a bit outdated but interesting read.
Try using a newer version of Excel for this. From your query it looks like you’re using Excel 97 – there are probably a ton of bugs and incompatibilities that exist in this version.
If this doesn’t help other options are:
- Do this manually from SSSM like Ozren suggested
- Try creating SSIS package for this
Here are couple other threads to get you started
http://www.connectionstrings.com/excel/
How do you transfer or export SQL Server 2005 data to Excel
Export SQL query data to Excel
Is there a way to do a batch update on SQL Server from a row of data in Excel? We have excel documents that contain 2000+ plus rows and need to be imported in SQL Server. Is there a way to do a batch insert of these guys without calling the database over and over to insert one row at a time?
SQL Server Integrations Services offers a wizard based import which can help you easily set up a package to import an excel file. You can even save the package and schedule it to repeat the import in the future.
You have other options, as well. If you save the excel file to a comma or tab delimited text file, you can use the BULK INSERT t-sql command. See an example on the sqlteam.com forums.
Another T-SQL option is SELECT INTO. Excel is a valid OLEDB or ODBC data source from T-SQL. Here's an example.
There's also a command line import tool included with Microsoft SQL Server called BCP. Good documentation on BCP and the other options can be found on MSDN at: http://msdn.microsoft.com/en-us/library/ms187042.aspx
You can create an SSIS package to read your Excel file. When you create your task, you can select a connection type of "Excel", and then it helps you create an "Excel Connection Manager". Then you can easily send the data to your SQL Server table. Here's a tutorial on how to import an Excel file into SQL Server (2005). Give it a look.
Yes! Use the import/export wizard of the SSMS! Use an Excel-source and a SQL Server destination. You can also create a SSIS-Package in the BIDS or use the BULK INSERT-statement from T-SQL, if you convert your Excel-sheets in to CSV-files.