Problem:
I have a table
CREATE TABLE BestTableEver
(
Id INT,
knownValue INT,
unknownValue INT DEFAULT 0,
totalValue INT DEFAULT 0);
And I have this CSV File (Loki.csv)
Id, knownValue, unknownValue, totalValue
1, 11114
2, 11135
3, 11235
I want to do a bulk insert into the table and since I do not know the values of unknownValue and totalValue yet , I want them to be take up the default value (as defined in the table creation)
My approach so far
create procedure populateLikeABoss
@i_filepath NVARCHAR(2048)
DECLARE @thor nvarchar(MAX)
SET @thor=
'BULK INSERT populateLikeABoss
FROM ' + char(39) + @i_filepath + char(39) +
'WITH
(
FIELDTERMINATOR = '','',
ROWTERMINATOR = ''\n'',
FIRSTROW = 2,
KEEPNULLS
)'
exec(@thor)
END
and calling the procedure to do the magic
populateLikeABoss 'C:\Loki.csv'
Error
Bulk load data conversion error (type mismatch or invalid character for the specified codepage) for row 2, column 2 (sizeOnMedia).
References
Keeping NULL value with bulk insert
Similar question without the answer I need