1 Sep 2011

BULK INSERT from CSV file


This is an example of BULK INSERT using CSV file.
This script can be used when you want to create a table using records in CSV file.
And I just noticed that the CSV file should be located in SQL server.
I don't know if there is any way to do that without moving the file to SQL server right now.



USE Safrock
CREATE TABLE #tempTable
(timestamp smalldatetime, mobilenumber varchar(50))
BULK INSERT #tempTable
FROM 'c:\SMSResponses-Reply2.csv'
WITH
(
FIRSTROW = 2,
FIELDTERMINATOR = ',',
ROWTERMINATOR = '\n'
)
SELECT * FROM #tempTable
INSERT INTO Log_Customer_Campaign_SMS
(ReceivedTime, Originator, Recipient, Text)
SELECT
timestamp
,mobilenumber
,'61427200812'
,'2'
FROM #tempTable
DROP TABLE #tempTable

0 comments:

Post a Comment