Last active
March 18, 2020 19:46
-
-
Save changhuixu/c2d4f4bc3166d4060184d11ddf36308c to your computer and use it in GitHub Desktop.
import csv file to SQL temp table
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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