|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
SQL Server 2000 - Importing text Files into SQL Server
Hi,
I have been unable to import a CSV file into SQL Server 2000. I have a CSV file - Hierarchy. When I open the file in textpad, here is what I see: 1. Each row is on a new line. 2. Each field is separated by a semi-colon. 3. The first line has the headers for the data. 4. At the end of the last field of the header column, I see a semi-colon. 5. All other rows have no commas at the end, just a new line seperation. (except a good part of lines) When I try to import the data from the textfile through a SQL Code (shown below), I get a message - "0 row(s) affected" The data gets imported into Excel 2007 perfectly. On looking into the file closely, some of the rows have semi-colon at the end of the row while some does not have. It seems that the data is truly not formatted in the right way. How can I import the file into SQL Server 2000? I have attached the sample data for your reference as well. Code:
--Import data into the Hierarchy Table from the Hierarchy.csv file
BULK INSERT Hierarchy
FROM 'C:\Sales_Ranking\Hierarchy.csv'
WITH
(
FIRSTROW = 2,
FIELDTERMINATOR = ',',
ROWTERMINATOR = '\n'
)
Thanks, |
|
#2
|
||||
|
||||
|
Have you tried using the DTS Wizard? Just load up Enterprise Manager and right-click on your database and select All Tasks -> Import Data -> Next. As your data source select "Text File" and specify your file name and click next.
You can then specify your text delimiter, end of line delimiter and text qualifier if necessary, make sure you tick the box to say that the first row contains column headings. Now just click next through the dialogs to see how your data will look and when you are happy click finish. The fact that some of your rows dont have a semi-colon on the end shouldnt matter if you use a VbCrLf (end of line character) as the row delimiter. If you have any problems let us know. |
|
#3
|
|||
|
|||
|
You are specifying the field terminator as ',' but the fields are actually terminated with a semi-colon ';'. Since that would cause it to read each row as a single field, it wouldn't match with the table definition in your database.
|
|
#4
|
|||
|
|||
|
I used the DTS Wizard. Please see the screen-shots in the attached word document. I am using a Text file. When I look into the text file, it shows a semi-colon. Despite the right value entered into the respective areas, it throws an error that it is not a valid delimiter.
If I convert these files into an Excel file, it works fine. But I do not want to convert them in excel. I want to be able to work directly by importing the data into the existing tables. Any ideas? |
|
#5
|
|||
|
|||
|
Did you try it using a semicolon as the field terminator. Then your DTS command would match your data file and it should import.
Code:
--Import data into the Hierarchy Table from the Hierarchy.csv file
BULK INSERT Hierarchy
FROM 'C:\Sales_Ranking\Hierarchy.csv'
WITH
(
FIRSTROW = 2,
FIELDTERMINATOR = ';',
ROWTERMINATOR = '\n'
)
|
|
#6
|
|||
|
|||
|
I am still having trouble importing data from the text file which is semi-colon separated.
Here is the structure of the Hierarchy table Code:
CREATE TABLE Hierarchy ( Version_Name char(50), Effective_Start_Date datetime, Position_Name varchar(200), Person_latest varchar(200), Parent_Position varchar(200), Parent_Person_latest varchar(200) ) --Bulk Insert data into Hierarchy table BULK INSERT Hierarchy FROM 'c:\Xactly\SourceData\Hierarchy.txt' WITH ( FIELDTERMINATOR = ';', ROWTERMINATOR = '\n' ) GO Also here are the first 10 rows of the source file as seen in the attachement. When I run the above, I get the errors as seen below: Code:
Server: Msg 4866, Level 17, State 66, Line 1 Bulk Insert fails. Column is too long in the data file for row 1, column 1. Make sure the field terminator and row terminator are specified correctly. Server: Msg 7399, Level 16, State 1, Line 1 OLE DB provider 'STREAM' reported an error. The provider did not give any information about the error. OLE DB error trace [OLE/DB Provider 'STREAM' IRowset::GetNextRows returned 0x80004005: The provider did not give any information about the error.]. The statement has been terminated. Last edited by zwieback89 : September 29th, 2009 at 05:09 PM. |
|
#7
|
|||
|
|||
|
hmm....Technically /n only indicates the line-feed portion of {cr}{lf} You might try using /r/n as the row terminator.
|
|
#8
|
|||
|
|||
|
Quote:
Even that does not work. I get the message "0 row(s) affected" Thanks, |
![]() |
| Viewing: ASP Free Forums > Database > Microsoft SQL Server > SQL Server 2000 - Importing text Files into SQL Server |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|