Pages

Saturday, June 1, 2013

How to import csv file with OPENROWSET?

Execute the following Microsoft SQL Server Transact-SQL script to demonstrate data import from .csv flat file using OPENROWSET applying 2 different providers. 
USE AdventureWorks2008;

EXEC sp_configure
GO
-- [Ad Hoc Distributed Queries] run_value should be 1

SELECT * FROM OPENROWSET('MSDASQL',
'Driver={Microsoft Text Driver (*.txt; *.csv)};
DefaultDir=F:\data\export\csv\;',
'SELECT * FROM Top10.csv')
GO

--Using a different provider
SELECT *
FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0',
'Text;Database=F:\data\export\csv\;HDR=YES',
'SELECT * FROM Top10.csv')
GO
Related article:

No comments:

Post a Comment