Microsoft SQL Server
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsDatabaseMicrosoft SQL Server

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old September 21st, 2009, 07:08 PM
zwieback89 zwieback89 is offline
Contributing User
ASP Free Novice (500 - 999 posts)
 
Join Date: Sep 2006
Location: California
Posts: 766 zwieback89 User rank is Sergeant (500 - 2000 Reputation Level)zwieback89 User rank is Sergeant (500 - 2000 Reputation Level)zwieback89 User rank is Sergeant (500 - 2000 Reputation Level)zwieback89 User rank is Sergeant (500 - 2000 Reputation Level)zwieback89 User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 6 Days 14 h 42 m 41 sec
Reputation Power: 21
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,
Attached Files
File Type: txt Hierarchy.txt (2.0 KB, 30 views)

Reply With Quote
  #2  
Old September 22nd, 2009, 04:09 AM
sync_or_swim's Avatar
sync_or_swim sync_or_swim is offline
Moderator
Click here for more information.
 
Join Date: Mar 2006
Location: South Wales
Posts: 3,461 sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Months 1 Day 16 h 50 m 26 sec
Reputation Power: 1806
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.

Reply With Quote
  #3  
Old September 22nd, 2009, 08:14 PM
gregory.owen@hp gregory.owen@hp is offline
Maniac
ASP Free Novice (500 - 999 posts)
 
Join Date: Sep 2003
Location: Sweet Home, Oregon
Posts: 598 gregory.owen@hp User rank is Sergeant Major (2000 - 5000 Reputation Level)gregory.owen@hp User rank is Sergeant Major (2000 - 5000 Reputation Level)gregory.owen@hp User rank is Sergeant Major (2000 - 5000 Reputation Level)gregory.owen@hp User rank is Sergeant Major (2000 - 5000 Reputation Level)gregory.owen@hp User rank is Sergeant Major (2000 - 5000 Reputation Level)gregory.owen@hp User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 3 Days 14 h 46 m 46 sec
Reputation Power: 37
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.

Reply With Quote
  #4  
Old September 25th, 2009, 02:39 PM
zwieback89 zwieback89 is offline
Contributing User
ASP Free Novice (500 - 999 posts)
 
Join Date: Sep 2006
Location: California
Posts: 766 zwieback89 User rank is Sergeant (500 - 2000 Reputation Level)zwieback89 User rank is Sergeant (500 - 2000 Reputation Level)zwieback89 User rank is Sergeant (500 - 2000 Reputation Level)zwieback89 User rank is Sergeant (500 - 2000 Reputation Level)zwieback89 User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 6 Days 14 h 42 m 41 sec
Reputation Power: 21
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?
Attached Files
File Type: doc SQL Import Error.doc (79.5 KB, 18 views)

Reply With Quote
  #5  
Old September 26th, 2009, 12:18 AM
gregory.owen@hp gregory.owen@hp is offline
Maniac
ASP Free Novice (500 - 999 posts)
 
Join Date: Sep 2003
Location: Sweet Home, Oregon
Posts: 598 gregory.owen@hp User rank is Sergeant Major (2000 - 5000 Reputation Level)gregory.owen@hp User rank is Sergeant Major (2000 - 5000 Reputation Level)gregory.owen@hp User rank is Sergeant Major (2000 - 5000 Reputation Level)gregory.owen@hp User rank is Sergeant Major (2000 - 5000 Reputation Level)gregory.owen@hp User rank is Sergeant Major (2000 - 5000 Reputation Level)gregory.owen@hp User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 3 Days 14 h 46 m 46 sec
Reputation Power: 37
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' 
)

Reply With Quote
  #6  
Old September 29th, 2009, 03:54 PM
zwieback89 zwieback89 is offline
Contributing User
ASP Free Novice (500 - 999 posts)
 
Join Date: Sep 2006
Location: California
Posts: 766 zwieback89 User rank is Sergeant (500 - 2000 Reputation Level)zwieback89 User rank is Sergeant (500 - 2000 Reputation Level)zwieback89 User rank is Sergeant (500 - 2000 Reputation Level)zwieback89 User rank is Sergeant (500 - 2000 Reputation Level)zwieback89 User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 6 Days 14 h 42 m 41 sec
Reputation Power: 21
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.

Reply With Quote
  #7  
Old September 29th, 2009, 11:47 PM
gregory.owen@hp gregory.owen@hp is offline
Maniac
ASP Free Novice (500 - 999 posts)
 
Join Date: Sep 2003
Location: Sweet Home, Oregon
Posts: 598 gregory.owen@hp User rank is Sergeant Major (2000 - 5000 Reputation Level)gregory.owen@hp User rank is Sergeant Major (2000 - 5000 Reputation Level)gregory.owen@hp User rank is Sergeant Major (2000 - 5000 Reputation Level)gregory.owen@hp User rank is Sergeant Major (2000 - 5000 Reputation Level)gregory.owen@hp User rank is Sergeant Major (2000 - 5000 Reputation Level)gregory.owen@hp User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 3 Days 14 h 46 m 46 sec
Reputation Power: 37
hmm....Technically /n only indicates the line-feed portion of {cr}{lf} You might try using /r/n as the row terminator.

Reply With Quote
  #8  
Old October 8th, 2009, 03:39 PM
zwieback89 zwieback89 is offline
Contributing User
ASP Free Novice (500 - 999 posts)
 
Join Date: Sep 2006
Location: California
Posts: 766 zwieback89 User rank is Sergeant (500 - 2000 Reputation Level)zwieback89 User rank is Sergeant (500 - 2000 Reputation Level)zwieback89 User rank is Sergeant (500 - 2000 Reputation Level)zwieback89 User rank is Sergeant (500 - 2000 Reputation Level)zwieback89 User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 6 Days 14 h 42 m 41 sec
Reputation Power: 21
Quote:
Originally Posted by gregory.owen@hp
hmm....Technically /n only indicates the line-feed portion of {cr}{lf} You might try using /r/n as the row terminator.


Even that does not work. I get the message "0 row(s) affected"

Thanks,

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseMicrosoft SQL Server > SQL Server 2000 - Importing text Files into SQL Server


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump





 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek