Importing Excel data into SQL Server 2005 - sql

Below SQL Query is fine when I execute in SQL Server 2008 but it is not working in SQL Server 2005.
SELECT * INTO "12-2014" FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0',
'Excel 8.0;Database=C:\ImportExcel\Test.xls', ['12-2014$'])
I am getting this error.
Msg 7403, Level 16, State 1, Line 1
The OLE DB provider "Microsoft.ACE.OLEDB.12.0" has not been registered.
Can anyone help please?

this thread should help you.
essentially this:
First, I want to inform that, Import and Export Data (32-bit) is the
default export tool when you right click a database to export data.
Let’s perform the following steps to export data from SQL Server to
Excel with Import and Export Data (64-bit):
Click Start, All Programs, Microsoft SQL Server 2008 folder, Import and Export Data (64-bit).
In “Choose a Data Source” step, please choose “SQL Server Native Client” as Data source, and specify your Server name and Database,
then click next.
In “Choose a Destination” step, please choose “Microsoft Office 12.0 Access Database Engine OLE DB Provider”, and then click “Properties…”
In “Data Link Properties”, under “Connection” tab, please fill out the Date Source (the excel file location, for example:
D:\Temp\temp.xlsx); under “All” tab, please double click “Extended
Properties”, and input “Excel 12.0” (without quotation) as its
property value, return to “Connection” tab and click “Test Connection”
and we will receive a message stating the connection succeeded, click
“OK”.
Click “Next” until the step “Select Source Tables and Views”, please select the table you want to export there and then click
“Next”.
Follow the wizard and finish the process.
You can also refer to the following link which shows how to import
data from Excel to SQL Server with screenshots:
http://hrvoje.piasevoli.com/2010/09/01/importing-data-from-64-bit-excel-in-ssis/

Related

Import Data to Excel Using SQL/OLE DB

I'm trying to recreate an excel file that I had found that imported data into a table using an OLE DB Query Connection that made use of a SQL server. When I go to the connection properties of the connection I'm trying to recreate, there's no connection file and the connection type states that it is an OLE DB Query. It has a lengthy connection string with the information of the SQL server and then the SQL command text that tells the query basically what to search for.
I am using the 2010 v. of Excel so I go to Data > From Other Sources > Data Connection Wizard > Other/Advanced....
I have no idea where to go from there. I've tried clicking on the OLE DB for SQL but it doesn't seem like it's right as it'll delete itself because there's apparently too much data from the query and it'll take too long to load.

Exporting a table from SQL Server 2008 R2 to a file WITHOUT external tools

I would like to export a table from SQL Server 2008 R2 to a file. The problem is that I don't have bcp (nor can I install it or anything else) and am not able to run xpcmdshell. Anyone have any ideas on how this could be done without those permissions/tools? (I would like to have this happen on some automated basis preferably)
I'm usually using Copy/Paste from SSMS Results Pane to Excel
OR
you can right click on database in the Object Explorer and select Database->Tasks->Export Data. An SQL Server Import and Export Wizard dialog opens and you will be able to export data from any table or query to the file or another destination.
OR
you can use LinqPad - awesome, simlpe and free tool (I really love it) that doesn't require installation
In the results pane, click the top-left cell to highlight all the records, and then right-click the top-left cell and click "Save Results As". One of the export options is CSV.
You can also use a command like this too:
INSERT INTO OPENROWSET ('Microsoft.Jet.OLEDB.4.0', 'Excel 8.0;Database=c:\Test.xls;','SELECT productid, price FROM dbo.product')
Lastly, you can look into using SSIS (replaced DTS) for data exports. Here is a link to a tutorial: http://www.accelebrate.com/sql_training/ssis_2008_tutorial.htm
If you have SQL Server 2012 you could add File Tables to your database. Thus you could use SQL Agent to schedule a simple stored proc to update the file table when desired.
http://technet.microsoft.com/en-us/library/ff929144.aspx#Description
it has something called "Query Analyzer"
Query Analyzer (isqlw.exe) is the SQL 2000, pre-SSMS, query tool. A very fine tool. Among other things, is capable of exporting query results to a file. See https://stackoverflow.com/a/3769766/105929:
go to the Tools -> Options menu. On the Results tab, choose to send your output to a CSV file and select the "Print column headers" option.

Importing Excel 2007 File Using SQL Server 2005

I have an excel 2007 file with about 301808 rows and 2 columns. I was trying to use SSIS to import but cant use 2007 excel. I then decided to try and make a linked server in SQL Server, Following the instructions here:
In SQL Server Management Studio, expand Server Objects in Object Explorer.
Right-click Linked Servers, and then click New linked server.
In the left pane, select the General page, and then follow these steps:
In the first text box, type any name for the linked server.
Select the Other data source option.
In the Provider list, click Microsoft Jet 4.0 OLE DB Provider.
In the Product name box, type Excel for the name of the OLE DB data source.
In the Data source box, type the full path and file name of the Excel file.
In the Provider string box, type Excel 8.0 for an Excel 2002, Excel 2000, or Excel 97 - workbook.
Click OK to create the new linked server.
From Here: http://support.microsoft.com/kb/306397/EN-US
However the instructions only covers previous excel files not 2007 so I looked up connection strings for 2007 and used Excel 12.0 instead of Excel 8.0 in settings of linked server:
Provider: Microsoft Office 12.0 Access Database Engine OLE DB
Provider Product Name: Excel Data source: C:\Documents and
Settings\UserName\Desktop\Main\FilesIns\MyExcelFile.xlsx Provider
String: Excel 12.0
Location:
Catalog:
I then got this error:
The OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "EXCEL_MY_FILE" does not contain the table "Report 1$". The table either does not exist or the current user does not have permissions on that table.
I went into security and added nt authority\system just in case it was permissions problem and it still gave me the error above.
The excel table is called 'Report 1'.
I also tried using openrowset in sql to see what happened and I got this:
SQL Server blocked access to STATEMENT 'OpenRowset/OpenDatasource' of component 'Ad Hoc Distributed Queries' because this component is turned off as part of the security configuration for this server.
I then tried the code in link below to see if it helped me use openrowset:
How to enable Ad Hoc Distributed Queries
EXEC sp_configure 'show advanced options', 1
RECONFIGURE
GO
EXEC sp_configure 'ad hoc distributed queries', 1
RECONFIGURE
GO
And got:
OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "(null)" returned message "Syntax error in FROM clause.".
Msg 7321, Level 16, State 2, Line 1
An error occurred while preparing the query "Select * from C:\Documents and Settings\UserName\Desktop\Main\FilesIns\MyExcelFile.xlsx" for execution against OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "(null)".
So I am not sure if the values in my openrowset statement are correct.
Really just looking for a way to import this file into an sql table without using SSIS - I cant use it anyway.
Thanks
Andrew
Under your sp_Reconfigure, see that you reference an article here.. However, I think you may need to go to Microsoft instead..
http://technet.microsoft.com/en-us/library/ms187569%28v=sql.90%29.aspx
And there are quite a few examples of how to use OPENROWSET here -
http://technet.microsoft.com/en-us/library/ms190312%28v=sql.90%29.aspx

In SQL Server 2000 how to convert table to text file

In SQL Server 2000, I need to convert a table data (whole, not partial) to a text file (csv or tab).
How can I do this with a table (tblCustomer) which has name, address, phone number, for example?
I don't use SQL Server Management Studio. I have many groups of stored procedures running on daily basis and just want to write a stored procedure to add in to one of the groups.
Are you using SQL Server Management Studio?
If so, just right click on the database name, and choose tasks->export data from the context menu, then follow the wizard.
You you are using Management studio, you can try this:
In your SQL Server Management Studio, right-click on the database where the table is and select Tasks->Export Data. This will bring up
the SQL Server Import and Export Wizard, which is very much similar to
the DTS Import/Export utility of SQL Server 2000.
Select your table from the "Choose a Data Source" screen then click on Next.
In the "Choose a Destination", select "Flat File Destination" as your Destination and enter the File name.
Just click on Next after that and you should be ok already.
You can also export it to xml using a query and then, on your app, convert it do csv. Check this out: FOR XML
Or, as #Aaron said, use The BCP Utility
EDIT
As you said you want the query way, I would go for the For XML and them parse the result to a CSV format. AFAIK, SQL server does not have an way of doing what you want automatically, so you will have to make it yourself. Also, you can adapt this sample.
Here and here you can find some scripts that may help you.

Convert SQL Server 2012 database to MS Access 2010

I have done all kind of tries. Naybe I have done something wrong. Can you suggest me how to import data from SQL Server to Access?
I did export from SQL Server (right click and task export)
I got errors like:
Error 0xc02020c4: Data Flow Task 1: The attempt to add a row to the
Data Flow task buffer failed with error code 0xC0047020. (SQL Server
Import and Export Wizard)
I did import from Access and I tried thru ODBC connection and it also failed.
If anyone has the exact steps or any converters software link then it will be great.