I try to insert data from a .csv to a MS SQL databse. I do it like this:
CREATE TABLE [dbo].[prescreen_candidateData](
[id] [varchar](50) DEFAULT '',
[email] [varchar](50) DEFAULT '',
[firstname] [varchar](50) DEFAULT '',
[lastname] [varchar](50) DEFAULT '',
[city] [varchar](50) DEFAULT '',
[address] [varchar](50) DEFAULT '',
[phone] [varchar](50) DEFAULT '',
[birthday] [varchar](50) DEFAULT '',
[candidateurl] [varchar](50) DEFAULT '',
[createdAt] [varchar](50) DEFAULT '') ON [PRIMARY]
After creation the table, I try to insert like:
BULK INSERT [dbo].[prescreen_candidateData] FROM '\\server2\prescreen$\candidateData.csv' WITH (
FIRSTROW = 2,
FIELDTERMINATOR = '\,',
ROWTERMINATOR = '\n',
KEEPNULLS
);
My .csv is build on like this:
id,email,firstname,lastname,city,address,phone,birthday,candidateurl,createdAt
for Example like:
58282,[email protected],Michael,Meier,,"""Street Nr 12,08159,City""",012345678910,"1996-08-29 00:00:00",https://linktoemployee, 2016-05-12
In my example, city is empty, in my csv it is shown like ,, that is okay, but my problem the adressfield, because adressfield contains , but the , is the terminator... how can I do it, that in the bulk insert the , whicht is between "" will be ignored?
Edit: **I solved it by creating a linked server to the csv... worked as I want **

ROWTERMINATOR = '\n'is ignored by sql server. InsteadROWTERMINATOR = '\r\n'will be used. Most of the time this will work, but not always. In order to use line feed as rowterminator useROWTERMINATOR = '0x0a'.