Solved

Import CSV file in SQL using Bulk insert

Posted on 2016-11-03
4
36 Views
Last Modified: 2016-11-03
Hello,

I have created the table that match exactly the header of the CSV file but when I  run the bulk insert query it returns ( 0 row(s) afftected)
CREATE TABLE [dbo].[TCountry](
	[CountryCode] [varchar](3) NULL,
	[IsValid] [char](1) NULL,
	[CountryDesignation] [varchar](150) NULL,
	[LCC] [char](1) NULL,
	[RegionCode] [nchar](10) NULL,
	[User] [varchar](50) NULL,
	[UpdateDateTime] [varchar](50) NULL
) ON [PRIMARY]

bulk insert TCountry from 'C:\COUNTRY.csv'
with ( FIELDTERMINATOR =';', FIRSTROW = 2 )

Open in new window

COUNTRY.csv
0
Comment
Question by:arnololo123
  • 2
4 Comments
 
LVL 46

Expert Comment

by:Vitor Montalvão
ID: 41872322
How did you create the CSV file?
It might need a ROWTERMINATOR also.
0
 
LVL 46

Accepted Solution

by:
Vitor Montalvão earned 500 total points
ID: 41872326
Try with the ROWTERMINATOR:
bulk insert TCountry from 'C:\temp\COUNTRY.csv'
with ( FIELDTERMINATOR =';', ROWTERMINATOR='0x0a',FIRSTROW = 2)

Open in new window

0
 
LVL 1

Expert Comment

by:PAGANED
ID: 41872345
Your problem stems from your CSV file
.
Change your CSV file into a TXT file , and it will work fine
Make sure the file at the location "C:\"  is on the SQL Server !
..........
bulk insert TCountry from 'C:\COUNTRY.txt'
with ( FIELDTERMINATOR =';', FIRSTROW = 2 )
...........
CountryCode;IsValid;CountryDesignation;LCC;RegionCode;User;UpdateDateTime
ABW;Y;Aruba;Y;ROW;youbi;2015-08-11T16:04:08
AFG;Y;Afghanistan;Y;ASI;youbi;2015-08-11T16:04:08
AGO;Y;Angola, Republic of;Y;ROW;youbi;2015-08-11T16:04:08
AIA;Y;Anguilla;Y;ROW;youbi;2015-08-11T16:04:08
ALB;Y;Albania, People's Socialist Republic of;Y;EUR;youbi;2015-08-11T16:04:08
AND;Y;Andorra, Principality of;Y;EUR;youbi;2015-08-11T16:04:08
ANT;Y;Netherlands Antilles;Y;ROW;youbi;2015-08-11T16:04:08
ARE;Y;United Arab Emirates;Y;ASI;youbi;2015-08-11T16:04:08
ARG;Y;ARGENTINA;Y;SAM;youbi;2015-08-11T16:04:08
ARM;Y;Armenia;Y;ASI;youbi;2015-08-11T16:04:08
ASM;Y;American Samoa;Y;ROW;youbi;2015-08-11T16:04:08
ATA;Y;Antarctica (the territory South of 60 deg S);Y;ROW;youbi;2015-06-16T15:49:31
ATF;Y;French Southern Territories;Y;ROW;youbi;2015-06-16T15:49:31
ATG;Y;Antigua and Barbuda;Y;ROW;youbi;2015-08-11T16:04:08
AUS;Y;Australia, Commonwealth of;N;ROW;youbi;2015-08-11T16:04:08
.
.
0
 

Author Closing Comment

by:arnololo123
ID: 41872365
great thanks
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now