Solved

Import CSV into Sql Server with OPENROWSET

Posted on 2010-08-16
1
1,099 Views
Last Modified: 2012-05-10
I'm trying to import a simple .csv into Sql Server 8 with OPENROWSET:

Select * FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0',
'Excel 8.0;Database=C:\IMPORTFILES\test.csv', 'SELECT * FROM [Sheet1$]')

I get the following error:

Server: Msg 7399, Level 16, State 1, Line 1
OLE DB provider 'Microsoft.Jet.OLEDB.4.0' reported an error. The provider did not give any information about the error.
OLE DB error trace [OLE/DB Provider 'Microsoft.Jet.OLEDB.4.0' IDBInitialize::Initialize returned 0x80004005:  The provider did not give any information about the error.].

I have verified the .csv file is valid and can be opened in Excel.  I've done this is the past without errors, can't see what's wrong this time.
0
Comment
Question by:kevbob650
1 Comment
 
LVL 7

Accepted Solution

by:
macentrap earned 500 total points
ID: 33450580
You are using .csv wont you be using Microsoft Text Driver??


SELECT * FROM OPENROWSET('MSDASQL', 'Driver={Microsoft Text Driver (*.txt; *.csv)};DEFAULTDIR=C:\IMPORTFILES\;Extensions=CSV;','SELECT * FROM test.csv')

With Excel I have used please try to add IMEX=1

I have used this in SQL 2008
UPDATE SL1
SET
SL1.QTY = T1.QTY                  

FROM  

(select * FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0',

'Excel 8.0;DATABASE=D:\qty.xls;IMEX=1','Select * from [Results$]'))AS T1,

Stock SL1
WHERE
T1.Code COLLATE DATABASE_DEFAULT  = SL1.Code COLLATE DATABASE_DEFAULT
and T1.Loc  = SL1.Loc
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SSRS - Date Report Options 2 27
Solar Winds can't see SQL Server Express 17 31
SQL Availablity Groups Shared Path 2 13
SQL Recursion 6 16
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Viewers will learn how the fundamental information of how to create a table.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question