arnololo123
asked on
Import CSV file in SQL using Bulk insert
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)
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 )
COUNTRY.csv
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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;Countr yDesignati on;LCC;Reg ionCode;Us er;UpdateD ateTime
ABW;Y;Aruba;Y;ROW;youbi;20 15-08-11T1 6:04:08
AFG;Y;Afghanistan;Y;ASI;yo ubi;2015-0 8-11T16:04 :08
AGO;Y;Angola, Republic of;Y;ROW;youbi;2015-08-11T 16:04:08
AIA;Y;Anguilla;Y;ROW;youbi ;2015-08-1 1T16:04:08
ALB;Y;Albania, People's Socialist Republic of;Y;EUR;youbi;2015-08-11T 16:04:08
AND;Y;Andorra, Principality of;Y;EUR;youbi;2015-08-11T 16:04:08
ANT;Y;Netherlands Antilles;Y;ROW;youbi;2015- 08-11T16:0 4:08
ARE;Y;United Arab Emirates;Y;ASI;youbi;2015- 08-11T16:0 4:08
ARG;Y;ARGENTINA;Y;SAM;youb i;2015-08- 11T16:04:0 8
ARM;Y;Armenia;Y;ASI;youbi; 2015-08-11 T16:04:08
ASM;Y;American Samoa;Y;ROW;youbi;2015-08- 11T16:04:0 8
ATA;Y;Antarctica (the territory South of 60 deg S);Y;ROW;youbi;2015-06-16T 15:49:31
ATF;Y;French Southern Territories;Y;ROW;youbi;20 15-06-16T1 5:49:31
ATG;Y;Antigua and Barbuda;Y;ROW;youbi;2015-0 8-11T16:04 :08
AUS;Y;Australia, Commonwealth of;N;ROW;youbi;2015-08-11T 16:04:08
.
.
.
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;Countr
ABW;Y;Aruba;Y;ROW;youbi;20
AFG;Y;Afghanistan;Y;ASI;yo
AGO;Y;Angola, Republic of;Y;ROW;youbi;2015-08-11T
AIA;Y;Anguilla;Y;ROW;youbi
ALB;Y;Albania, People's Socialist Republic of;Y;EUR;youbi;2015-08-11T
AND;Y;Andorra, Principality of;Y;EUR;youbi;2015-08-11T
ANT;Y;Netherlands Antilles;Y;ROW;youbi;2015-
ARE;Y;United Arab Emirates;Y;ASI;youbi;2015-
ARG;Y;ARGENTINA;Y;SAM;youb
ARM;Y;Armenia;Y;ASI;youbi;
ASM;Y;American Samoa;Y;ROW;youbi;2015-08-
ATA;Y;Antarctica (the territory South of 60 deg S);Y;ROW;youbi;2015-06-16T
ATF;Y;French Southern Territories;Y;ROW;youbi;20
ATG;Y;Antigua and Barbuda;Y;ROW;youbi;2015-0
AUS;Y;Australia, Commonwealth of;N;ROW;youbi;2015-08-11T
.
.
ASKER
great thanks
It might need a ROWTERMINATOR also.