Import CSV file into SQL Server

0 votes

I have a few fundamental questions and I need assistance importing a.csv file into SQL Server using BULK INSERT.

Issues:

  • How can I make the import process handle the data that may have a comma (,) in between it in the CSV file (for example, the description)?
  • The data with commas are surrounded in "" (double quotes) [as in the example below] if the customer prepares the CSV from Excel. How can the import manage this, then?
  • How can we determine which rows the import skipped because of incorrect data? When importing, rows that cannot be imported are skipped.

Here is the sample CSV with the header:

Name,Class,Subject,ExamDate,Mark,Description
Prabhat,4,Math,2/10/2013,25,Test data for prabhat.
Murari,5,Science,2/11/2013,24,"Test data for his's test, where we can test 2nd ROW, Test."
sanjay,4,Science,,25,Test Only.

The SQL statement to import:

BULK INSERT SchoolsTemp
FROM 'C:\CSVData\Schools.csv'
WITH
(
    FIRSTROW = 2,
    FIELDTERMINATOR = ',',  --CSV field delimiter
    ROWTERMINATOR = '\n',   --Use to shift the control to next row
    TABLOCK
)

Can someone please help me with this?

Aug 14 in Database by Kithuzzz
• 11,040 points
38 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Database

0 votes
1 answer

How can I import an Excel file into SQL Server?

You can use OPENROWSET to import an Excel file ...READ MORE

answered Sep 15 in Database by narikkadan
• 18,480 points
31 views
0 votes
0 answers

Import .bak file to a database in SQL server

I have a file with .bak extension. How ...READ MORE

Aug 14 in Database by Kithuzzz
• 11,040 points
12 views
0 votes
1 answer

Error:Import SQL dump into PostgreSQL database

Hello, Here is the command you are looking ...READ MORE

answered May 4, 2020 in Database by Niroj
• 82,780 points
2,467 views
0 votes
1 answer

ORACLE LIVE SQL IMPORT CSV DATA (live oracle sql)

Convert CSV to SQL http://www.convertcsv.com/csv-to-sql.htm This programme may be ...READ MORE

answered Feb 11 in Database by Neha
• 8,920 points
2,983 views
0 votes
1 answer

Convert Date format into DD/MMM/YYYY format in SQL Server

Using convert() and style 106, you can ...READ MORE

answered Feb 23 in Database by Vaani
• 7,020 points
3,794 views
0 votes
0 answers
0 votes
1 answer

Calculate Time Intersection to Correlate Sequences of Independent Events

I think this solution requires a CROSS JOIN implementation. ...READ MORE

answered Oct 26, 2018 in Power BI by Upasana
• 8,620 points
329 views
0 votes
1 answer

How do I UPDATE from a SELECT in SQL Server?

MERGE INTO YourTable T USING ...READ MORE

answered Feb 3 in Database by Vaani
• 7,020 points
114 views
0 votes
0 answers

How do I UPDATE from a SELECT in SQL Server?

INSERT INTO Table (col1, col2, col3) SELECT col1, ...READ MORE

Feb 4 in Database by Vaani
• 7,020 points
41 views
0 votes
1 answer

What is a stored procedure?

A stored procedure is a set of ...READ MORE

answered Feb 4 in Database by Neha
• 8,920 points
210 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP