Skip to content

Instantly share code, notes, and snippets.

@changhuixu
Last active March 18, 2020 19:46
Show Gist options
  • Save changhuixu/c2d4f4bc3166d4060184d11ddf36308c to your computer and use it in GitHub Desktop.
Save changhuixu/c2d4f4bc3166d4060184d11ddf36308c to your computer and use it in GitHub Desktop.
import csv file to SQL temp table
IF OBJECT_ID('tempdb..#temp', 'U') IS NOT NULL DROP TABLE #temp;
CREATE TABLE #temp (
ID int NOT NULL,
[Name] nvarchar(50)
);
BULK INSERT #temp
FROM 'C:\AppData\fruits.csv' -- CSV file path
WITH
(
FORMAT = 'CSV',
FIELDQUOTE = '"', -- Default value
FIRSTROW = 2, -- Start import from the 2nd row
FIELDTERMINATOR = ',', -- CSV field delimiter
ROWTERMINATOR = '\n', -- Use to shift the control to next row
TABLOCK
);
SELECT * FROM #temp;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment