Enable Ad Hoc Distributed Queries. Run following code in SQL Server Management Studio – Query Editor.
EXEC sp_configure 'show advanced options', 1;
GO
RECONFIGURE;
GO
EXEC sp_configure 'Ad Hoc Distributed Queries', 1;
GO
RECONFIGURE;
GO
Create Excel Spreadsheet in root directory c:\contact.xls (Make sure you name it contact.xls). Open spreadsheet, on the first tab of Sheet1, create two columns with FirstName, LastName. Alternatively you can download sample Spreadsheet from here.
Run following code in SQL Server Management Studio – Query Editor.
USE [AdventureWorks];
GO
INSERT INTO OPENROWSET ('Microsoft.Jet.OLEDB.4.0', 'Excel 8.0;Database=c:\contact.xls;',
'SELECT * FROM [Sheet1$]')
SELECT TOP 5 FirstName, LastName
FROM Person.Contact
GO
Open contact.xls spreadsheet you will see first five records of the Person.Contact inserted into the first two columns.
Make sure your spreadsheet is closed during this operation. If it is open it may thrown an error. You can change your spreadsheet name as well name of the Sheet1 to your desired name.
Reference : Pinal Dave (http://blog.SQLAuthority.com)




Hi, this codes work great but how about it done by reverse..
like i have database in Access file in my C: drive then i want this to insert my SQL server database..
how could i do this..?
please help…
More informations are available here
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=49926
Edgar
Use Import/Export wizard from SQL Server
or read about OPENROWSET in sql server help file
when ever I tried to execute the below query it gives me an error.
INSERT INTO OPENROWSET (‘Microsoft.Jet.OLEDB.4.0′, ‘Excel 8.0;Database=c:\contact.xls;’,
‘SELECT * FROM [Sheet1]‘)
SELECT top 5 TXEM_Name as FirstName,TXEM_TaxPercentage as LastName
FROM ACCTaxMaster where txem_id>32
The error is :
OLE DB provider “Microsoft.Jet.OLEDB.4.0″ for linked server “(null)” returned message “The Microsoft Jet database engine could not find the object ‘Sheet1′. Make sure the object exists and that you spell its name and the path name correctly.”.
Msg 7350, Level 16, State 2, Line 1
Cannot get the column information from OLE DB provider “Microsoft.Jet.OLEDB.4.0″ for linked server “(null)”.
Pls reply.
thanks for advice.. all i saw there is inserting data using excel to SQL server. my question how about inserting data using access to SQL SERVER….
HOW COULD I DO IT..?
PLEASE HELP..
yes that is the error but i got correct link or path… and filename..
hi, i tried this codes to transfer my data from access to sql server…
but it’s not working…
can someone modify my codes please..?
Insert into magpatoc.dbo.RSOTransfer
Select * FROM (‘Provider=Microsoft.Jet.OLEDB.4.0;’,
‘Data Source=c:\CopyOfRSODB.mdb;User Id=admin;Password=;’,
‘SELECT * FROM FinalCustItemRSO’)
Help please..
when ever I tried to execute the below query it gives me an error.
INSERT INTO OPENROWSET (’Microsoft.Jet.OLEDB.4.0′, ‘Excel 8.0;Database=c:\contact.xls;’,
‘SELECT * FROM [Sheet1]’)
SELECT top 5 TXEM_Name as FirstName,TXEM_TaxPercentage as LastName
FROM ACCTaxMaster where txem_id>32
The error is :
Msg 208, Level 16, State 1, Line 1
Invalid object name ‘Person.Contact’.
ed9teen and neeraj instead of [Sheet1] write [Sheet1$]
Is it possible to set a nullable column as a Foreign key
to PrimaryKey Column of another table?
Siva.
thankx
its also can do using DTSWizard.exe in command Prompt or in RUN in windows
Thankx
sir,
i m working in sql server 2000, now i want to import server 2000 data in sql server 2005 ,how can i do this…help me plz
hi Dave
Trying to export a lot of data into Excel file but I get this error:
Msg 8152, Level 16, State 4, Line 1
String or binary data would be truncated.
The statement has been terminated.
I think it’s because there are line breaks and other characters in the data. Is there any way to get around this?
Thanks a lot!
TITLE: Microsoft SQL Server Management Studio
——————————
An exception occurred while executing a Transact-SQL statement or batch. (Microsoft.SqlServer.ConnectionInfo)
——————————
ADDITIONAL INFORMATION:
String or binary data would be truncated. (Microsoft SQL Server, Error: 8152)
For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=09.00.3033&EvtSrc=MSSQLServer&EvtID=8152&LinkId=20476
——————————
BUTTONS:
OK
——————————
OLE DB provider “Microsoft.Jet.OLEDB.4.0″ for linked server “(null)” returned message “The Microsoft Jet database engine could not find the object ‘Sheet1′. Make sure the object exists and that you spell its name and the path name correctly.”.
Msg 7350, Level 16, State 2, Line 1
Cannot get the column information from OLE DB provider “Microsoft.Jet.OLEDB.4.0″ for linked server “(null)”.
Hi – I would like to do something very similar…
I want all of the databases tables and their columns inserted into an excel spreadsheet. So schema rather than data.
Do you know how this can be done?
Sean, see the SQL Server help for “Information Schema”, it’s a set of “meta-tables” (or views) which contain information about your database’s schema.
Puinal Hi:
Is there a way to use query like below………..BUT NOT give column names hardcoded in the excel file….
The reason being my sql is dynamically being passed and I donot want to have column names hardcoded into my excel template.
USE [AdventureWorks];
GO
INSERT INTO OPENROWSET (‘Microsoft.Jet.OLEDB.4.0′, ‘Excel 8.0;Database=c:\contact.xls;’,
‘SELECT * FROM [Sheet1$]‘)
SELECT TOP 5 FirstName, LastName
FROM Person.Contact
GO
if exceed field length 255 then how?
anyone can help or not
Hi,
I used your code
USE [AdventureWorks];
GO
INSERT INTO OPENROWSET (‘Microsoft.Jet.OLEDB.4.0′, ‘Excel 8.0;Database=c:\contact.xls;’,
‘SELECT * FROM [Sheet1$]‘)
SELECT TOP 5 FirstName, LastName
FROM Person.Contact
GO
to export data from sql server to excel but i am getting this error
OLE DB provider “Microsoft.Jet.OLEDB.4.0″ for linked server “(null)” returned message “The Microsoft Jet database engine could not find the object ‘SheetData1$’. Make sure the object exists and that you spell its name and the path name correctly.”.
Msg 7350, Level 16, State 2, Line 1
Cannot get the column information from OLE DB provider “Microsoft.Jet.OLEDB.4.0″ for linked server “(null)”.
can you help me out to get rid of this?
Thanks!
Monika
Hi,
I have problem with Excel when I using Openrowset in sql 2k.
When I export sql table witch has column type decimal in excel I have column type string. I would like decimal in excel too.
What I can do?
THX
Hi,
This Query runs successfully
SELECT *
FROM OPENROWSET(‘Microsoft.Jet.OLEDB.4.0′,’c:\mydb.mdb’;'Admin’;”, Table1)
But this doesnt because it has password
SELECT *
FROM OPENROWSET(‘Microsoft.Jet.OLEDB.4.0′,’c:\ACCESS.mdb’;'Admin’;'mypwd’, Table1)
Before it both queries giving authentication error but after setting the permissions i am able to run the first query, but i am still having problem to run second query
Hi,
I am trying to create SSIS to export data to excel sheets(to multible sheets from different queries using views)
I tried to run one query and export to one of the sheets.
I got this error
[Excel Destination [153]] Error: SSIS Error Code DTS_E_OLEDBERROR. An OLE DB error has occurred. Error code: 0×80004005.
[Excel Destination [153]] Error: SSIS Error Code DTS_E_INDUCEDTRANSFORMFAILUREONERROR. The “input “Excel Destination Input” (164)” failed because error code 0xC020907B occurred, and the error row disposition on “input “Excel Destination Input” (164)” specifies failure on error. An error occurred on the specified object of the specified component. There may be error messages posted before this with more information about the failure.
and more…
Pinal or some Gurus ,
do you know how should I export data to excel from
2005 using SSIS?
priya
I am adding this to my above question
I need to insert data from B6
when ever I tried to execute the below query it gives me an error.
USE [TEST];
GO
INSERT INTO OPENROWSET (‘Microsoft.Jet.OLEDB.4.0′, ‘Excel 8.0;Database=c:\TEST.xls;’,
‘SELECT * FROM [Sheet1$]‘)
SELECT * FROM t11
GO
The error is :
OLE DB provider “Microsoft.Jet.OLEDB.4.0″ for linked server “(null)” returned message “The Microsoft Jet database engine could not find the object ‘Sheet1′. Make sure the object exists and that you spell its name and the path name correctly.”.
Msg 7350, Level 16, State 2, Line 1
Cannot get the column information from OLE DB provider “Microsoft.Jet.OLEDB.4.0″ for linked server “(null)”.
Pls reply.
Hello,
“OLE DB provider “Microsoft.Jet.OLEDB.4.0″ for linked server “(null)” returned message “The Microsoft Jet database engine could not find the object ‘Sheet1′. Make sure the object exists and that you spell its name and the path name correctly.”. ”
this error means your excel file do not have a sheet named Sheet1, so check the excel file
This is not still working anybody know, how to overcome on this error
“OLE DB provider “Microsoft.Jet.OLEDB.4.0″ for linked server “(null)” returned message “The Microsoft Jet database engine could not find the object ‘Sheet1′. Make sure the object exists and that you spell its name and the path name correctly.”. ”
Regards
Shyam
OLE DB provider “Microsoft.Jet.OLEDB.4.0″ for linked server “(null)” returned message “Could not find installable ISAM.”.
Msg 7303, Level 16, State 1, Line 1
Cannot initialize the data source object of OLE DB provider “Microsoft.Jet.OLEDB.4.0″ for linked server “(null)”.
Works great, thanks
We use SQL Server 2005 & SQL Server Express to keep our Management Software data.
My question is simple, but may not be so easily implemented. I would like to take our data (*.mdf) files and export it to a different work station that has also SQL Server Express. From my understanding this is not easily done thru SQL Server 2005. Does anyone have any suggestions?
hi, please help, i’m new to this sql…i’m running sql server 2005 on ms server 2003(64x). everytime i click on management studio this is the message i get “The file C:\windows\microsoft.net\framework\\mscorlib.tlb could not be loaded. An attempt to repair this condition failed because the file could not be found. Please reinstall this program.”
USE [AdventureWorks];
GO
INSERT INTO OPENROWSET (‘Microsoft.Jet.OLEDB.4.0′, ‘Excel 8.0;Database=c:\contact.xls;’,
‘SELECT * FROM [Sheet1$]‘)
SELECT TOP 5 FirstName, LastName
FROM Person.Contact
GO
This code is working properly, but when i changed the path of excel file then it gives an error(Note:- excel file is on anthoer machine)
path is like that :- \\bhavin\AX-Config\contact.xls
Error :- Msg 7399, Level 16, State 1, Line 1
The OLE DB provider “Microsoft.Jet.OLEDB.4.0″ for linked server “(null)” reported an error. The provider did not give any information about the error.
Msg 7303, Level 16, State 1, Line 1
Cannot initialize the data source object of OLE DB provider “Microsoft.Jet.OLEDB.4.0″ for linked server “(null)”.
INSERT INTO OPENROWSET (‘Microsoft.Jet.OLEDB.4.0′, ‘Excel 8.0;Database=D:\UserRights.xls;’,
‘SELECT * FROM [Sheet1]‘)
select * from dbtemp.dbo.Operators
here dbtemp is the database name and Operators is the table name
i have already created the file ‘D:\UserRights.xls;’
While using this query, i m getting following error whot should i do
Server: Msg 7399, Level 16, State 1, Line 1
OLE DB provider ‘Microsoft.Jet.OLEDB.4.0′ reported an error.
[OLE/DB provider returned message: The Microsoft Jet database engine could not find the object 'Sheet1'. Make sure the object exists and that you spell its name and the path name correctly.]
OLE DB error trace [OLE/DB Provider 'Microsoft.Jet.OLEDB.4.0' IColumnsInfo::GetColumnsInfo returned 0x80004005: ].
PLs Reply soon……..
can anyone please post the solution to this problem
Cannot get the column information from OLE DB provider “Microsoft.Jet.OLEDB.4.0″ for linked server “(null)”.
Hi,
The code provided works fine, but when i run the same second time the data in excel gets appended, where i want it to copy to a new sheet or delete the existing data and insert new data.. Awaiting for the response…
Thanks in advance
Hi, I would like to export data from store procedure (which has two input parameter) to Excel. The store procedure will return multipal record sets.
Please let me know if we have any way to do this.
Sorry forgot to mension n think this is required.
I am using Sql Server Express 2005.
I have procudures that successfully download data into Excel worksheets but run into issues if a field on the SQL Server has more than 255 characters it fails. I am using Excel 2003 and have found some post regarding “Extended Properties” of the connection string however I cannot get this to work correctly.
Do you have any suggestions on how to get around this type of issue?
I tried u r code
It is showing Error
Server: Msg 7399, Level 16, State 1, Line 1
OLE DB provider ‘Microsoft.Jet.OLEDB.4.0′ reported an error.
[OLE/DB provider returned message: The Microsoft Jet database engine could not find the object 'Sheet1'. Make sure the object exists and that you spell its name and the path name correctly.]
what is exact prob
is it with Excel Or with Sql
plz help
The reason many are getting this message:
[ “Microsoft.Jet.OLEDB.4.0″ for linked server “(null)” ] is because Excel must exist on the same machine you have the xls file on. The spreadsheet itself does not carry the Jet database engine.
hi dave i tried above code its working for excel but i want to export data from access data base to sql server and vise versa how can do this
pls help me i am a ferser……………..
@Rizwan
There are a tleast 5 ways of doing this, please look at the below link for more details.
http://support.microsoft.com/kb/321686
IM
Hi,
INSERT INTO OPENROWSET (‘Microsoft.Jet.OLEDB.4.0′, ‘Excel 8.0;Database=C:\temp\test.xls;’,
‘SELECT aftercare_id,participant_id,r_followup_period_id FROM [Sheet1$]‘)
SELECT [aftercare_id],[participant_id],[r_followup_period_id]
FROM view_1
go
The above code works, but it will allow me to put only 7 columns, if i put ‘*’ it is not inserting data into excel, could you please tell me how to fix this problem
i have 30 columns in my view. i want to use all columns, could you please respond to me as early as possible.
Thanks,
Roy
@Jith,
Sample from below link :
insert into OPENROWSET(‘Microsoft.Jet.OLEDB.4.0′,
‘Excel 8.0;Database=D:\testing.xls;’,
‘SELECT * FROM [SheetName$]‘) select * from SQLServerTable
Please visit this link to get more details.
Link : http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=49926
~ IM.
Hi,
I have a problem here. My codes works well. Everything seems fine. My problem is, whenever I upload large files like 18 mb .xls file, It shows page cannot be displayed. I’m working with a project for a large scale company. I really need this. this one works in SQLquery but not in my app. I hope someone would help me quick. INSERT INTO dbo.data SELECT * FROM OPENROWSET(‘Microsoft.Jet.OLEDB.4.0′,
‘Excel 8.0;Database=C:\Documents and Settings\…analysis.xls’, [data$])
you can contact me here: jaythree03@gmail.com
Error 0xc00470fe: Data Flow Task: The product level is insufficient for component “Destination – Configuration” (37).
(SQL Server Import and Export Wizard)
Hi I’ve tried this example with minor changes like:
INSERT INTO OPENROWSET (‘Microsoft.ACE.OLEDB.12.0;Database=C:\Documents and Settings\Thato\My Documents\contact.xlsx;’,'SELECT * FROM [Sheet1$]‘)
SELECT TOP 5 CallName, Surname
FROM DTIHeadcount
Where Period = 200904
——————–
I get a syntax error:
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near ‘)’.
Please help
In a simple way, we can export the resultset to .csv file using the following scenario:
1. Go to Tools>>Options>>Query Results>>Sql Server>>Results to text: specify the output format to “Tab delimited”
2.While executing the query – set Resultset to show as text instead of in grid (Ctrl + Q + T)
3. Select all from the Resultset and save Results as “name.csv” or “name.xls”
- Praveen
Hi!!!
Is possible to insert data from SQL Server to an Excel Spreadsheet that has a password protection? I need this because I want to prevent User Editing…
Tks a lot!!!
Great topic. Thanks
Worked for me, thanks!
I can’t find the URL that I wanted to cite, but just to let folks know, the “Jet” drivers for this type of wonderful thing are not supported on the 64 bit version of SQL Server. Nice, huh?
Error :- Msg 7399, Level 16, State 1, Line 1
The OLE DB provider “Microsoft.Jet.OLEDB.4.0″ for linked server “(null)” reported an error. The provider did not give any information about the error.
Msg 7303, Level 16, State 1, Line 1
Cannot initialize the data source object of OLE DB provider “Microsoft.Jet.OLEDB.4.0″ for linked server “(null)”.
Solution :
Make sure your the file path and SQL server are in the same PC
Hello sir,
For the solution you gave regarding exporting data from SQL server to Excel sheet, is there any alternative that the file should be manually created along wid a header row.
Is there any way the excel sheet too can be created with a header row defined by running a command line script from the sql promt so that the file along wid header is created at the same time just before data is inserted into that excel sheet i.e creating a dynamic query in which the file path , filename, column headers are specified in variables
Please help out.
Thanx
USE [hrnew];
GO
INSERT INTO OPENROWSET (‘Microsoft.Jet.OLEDB.4.0′, ‘Excel 8.0;Database=d:\12345.xls;’,'SELECT * FROM [Sheet1$]‘)
SELECT TOP 5 EMP_NO,EMP_FULL_NAME_AR FROM dbo.EMPLOYEES
GO
after run your script with my data i get the next error messge.
please help me
Msg 213, Level 16, State 1, Line 1
Insert Error: Column name or number of supplied values does not match table definition.
Hi, to all above that got the error :
The OLE DB provider “Microsoft.Jet.OLEDB.4.0″ for linked server “(null)” reported an error. The provider did not give any information about the error.
Ensure that you have a space between Excel and 8.0 in the OPENROWSET section ie
INSERT INTO OPENROWSET (‘Microsoft.Jet.OLEDB.4.0′,
‘Excel 8.0; Database=c:\somesheet.xls;’
,’SELECT * FROM [Sheet1$]‘)
to mahmoud
You generally see this type of error if you have not put the Column headers into Sheet1 of your spreadsheet .
ColumnHeaders must be the same as the Field Names.
Thanks this works great.
One problem I am having. Numeric fields that I am exporting to excel are entered into the excel sheet as text.
I have formatted the column in the excel sheet to number and I am still getting text. Any ideas how to fix this?
Thanks
Hi Every one,this good and simple. I tried this but it is not Working For me.after that working fine because the same syntax could not be worked for Excel 2007.Finally i got and if we use .xls format and also it will give error if an excel file is open and also for wrong name and also for columns not mentioned
hi
I tried the same but i get th following error
OLE DB provider “Microsoft.Jet.OLEDB.4.0″ for linked server “(null)” returned message “The Microsoft Jet database engine could not find the object ‘Sheet1$’. Make sure the object exists and that you spell its name and the path name correctly.”.
Msg 7350, Level 16, State 2, Line 1
Cannot get the column information from OLE DB provider “Microsoft.Jet.OLEDB.4.0″ for linked server “(null)”.
Can u please help me how to solve this ,
can i use the same in server 2008.
Please help me