DATETIME SELECT SELECT INTO DATE PAD STRING DYNAMIC SQL CURSOR MONEY FORMAT PERCENT STORED PROCEDURE SQL SERVER AGENT JOB OPTIMIZATION WHILE LOOP OVER PARTITION BY UPDATE
 
 
SITE SEARCH SQLUSA.com VIDEOS
 
 
SQL E/BOOKS   WORLD, USA & SQL NEWS   FORMAT
SCRIPTS SQL 2005 SQL 2008 ARTICLES
How to import csv file with OPENROWSET?

Execute the following Microsoft SQL Server T-SQL script to demonstrate data import from .csv flat file using OPENROWSET applying 2 different providers and applying BULK INSERT.

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

------------
 
-- T-SQL import local csv file with BULK INSERT
BULK INSERT InventoryDB.dbo.InvStage
   FROM 'C:\data\importstage\ukinventory.csv'
   WITH
      (
        FIELDTERMINATOR = ',',
        ROWTERMINATOR = '\n'
      )

------------

 

Exam Prep 70-461
SQL 2016 DESIGN & PROGRAMMING
 
 
 
DATETIME SELECT SELECT INTO DATE PAD STRING DYNAMIC SQL CURSOR MONEY FORMAT PERCENT STORED PROCEDURE SQL SERVER AGENT JOB OPTIMIZATION WHILE LOOP OVER PARTITION BY UPDATE