Answered by:
Bulk Insert with Null Value

Question
-
I'm having trouble inserting null value from a bulk insert statement.
The first Row inserted successfully,but the second not.i also checked with CHECK_CONSTRAINTS,but the problem remains
please help me
Here is an extract of the csv file:
First Name, Last Name, Age Name1,HK,23 Name2,YH,
Here the bulk Insert statement:
Bulk insert dbsct
FROM 'C:\Test1\dstd.CSV'
WITH (
FIRSTROW = 2,
FIELDTERMINATOR =',',
ROWTERMINATOR = '\n'
KEEPNULLS
)
Thursday, December 10, 2015 6:59 PM
Answers
-
- Proposed as answer by André Renato Furtado Friday, December 11, 2015 2:34 PM
- Marked as answer by Lydia ZhangMicrosoft contingent staff Monday, December 21, 2015 7:52 AM
Friday, December 11, 2015 12:10 PM
All replies
-
-
(1 row(s) affected).
no.
First Name Varchar(100)
Last Name Varchar(100)
Age int
- Edited by Hrishi K Friday, December 11, 2015 9:51 AM
Friday, December 11, 2015 7:44 AM -
-
sorry.there is no blank line after the last line
and also there is no blank line between the rows
- Edited by Hrishi K Friday, December 11, 2015 9:53 AM
Friday, December 11, 2015 9:42 AM -
I did tests with the data you published and functioned normally.
Reinforcing the Erland's thesis: How does your table definition look like?
Friday, December 11, 2015 11:10 AM -
Table dbsct
First Name Varchar(100)
Last Name Varchar(100)
Age int
CSV file
First Name, Last Name, Age Name1,HK,23 Name2,YH,
Bulk insert dbsct
FROM 'C:\Test1\dstd.CSV'
WITH (
FIRSTROW = 2,
FIELDTERMINATOR =',',
ROWTERMINATOR = '\n'
KEEPNULLS
)The last row not added
- Edited by Hrishi K Friday, December 11, 2015 11:34 AM
Friday, December 11, 2015 11:30 AM -
Make sure to keep an space in the NULL field when it is the last column(Age column in the second row).
- Edited by André Renato Furtado Friday, December 11, 2015 11:43 AM
Friday, December 11, 2015 11:41 AM -
now its working.
But the csv file is already generated.i can't modify it.
there is any other option
Thanks for your valuable reply.
- Edited by Hrishi K Friday, December 11, 2015 11:52 AM
Friday, December 11, 2015 11:52 AM -
- Proposed as answer by André Renato Furtado Friday, December 11, 2015 2:34 PM
- Marked as answer by Lydia ZhangMicrosoft contingent staff Monday, December 21, 2015 7:52 AM
Friday, December 11, 2015 12:10 PM -
Use Notepad++ to replace the expression ",\r\n" by ", \r\n".
Ignore quotation marks in expression.
Friday, December 11, 2015 2:34 PM