Click here to Skip to main content
15,890,609 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear,

I'm inserting CSV data into SQL Server.
Below is the code.

SQL
BULK
INSERT AA_Temp
FROM 'D:\A\33.csv'
WITH
(
FIELDTERMINATOR = ',',
ROWTERMINATOR = '\n'
)
GO


What my problem is my CSV file has a header, without having header is successfully inserted.

How to skip the first header, i tried above code but got error type mismatch beocz of getting first header row.

Thanks
Basit
Posted

1 solution

SQL
BULK
INSERT AA_Temp
FROM 'D:\A\33.csv'
WITH
(
FIELDTERMINATOR = ',',
ROWTERMINATOR = '\n',
FIRSTROW = 2
)
GO

How to skip first row, it's easy use FIRSTROW = n, where n is the row number from where you want to insert record, nth row will be treated as first row, read more[^]

-KR
 
Share this answer
 
Comments
basitsar 2-Nov-15 23:36pm    
Thanks A lot dear, But when i used this showing (0 row(s) affected), and when i deleted header then it inserted rows.
Thanks
Basit.
Krunal Rohit 3-Nov-15 0:01am    
Did you follow that link ?

-KR
basitsar 3-Nov-15 0:07am    
Thanks problem Solved

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900