Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old December 22nd, 2006, 01:43 AM
Authorized User
 
Join Date: Dec 2006
Location: chennai, tn, India.
Posts: 62
Thanks: 0
Thanked 0 Times in 0 Posts
Default Import Fixed length - SQL SERVER 2000

Hi all,

I need to import the data from flat file to SQL 2000.
My flat file has fixed length but no delimeters.

For eg.

Firstname varchar(20)
Lastname varchar(10)
Age int

Pls help in resolving the issue...

Chandru
__________________
Thanks,
Chandra
Reply With Quote
  #2 (permalink)  
Old December 22nd, 2006, 02:02 AM
Friend of Wrox
Points: 1,536, Level: 15
Points: 1,536, Level: 15 Points: 1,536, Level: 15 Points: 1,536, Level: 15
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2006
Location: , MI, USA.
Posts: 475
Thanks: 0
Thanked 9 Times in 9 Posts
Default

You can do it one of two ways...

1. Import the whole line into a single varchar column in a staging table and use substring to split it...
2. Create a BCP format file to identify how to do the split (can be used with BCP or BulkInsert). See Books OnLine for more info on how to build the format file.

--Jeff Moden
Reply With Quote
  #3 (permalink)  
Old December 22nd, 2006, 05:21 AM
Authorized User
 
Join Date: Dec 2006
Location: chennai, tn, India.
Posts: 62
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanx for the reply.
It would be better to provide some eg in BCP/Bulk Insert so that i can work around the said problem.
Creating a staging table and then splitting is a tedious job, so i would prefer to go for BCP/Bulk Insert.

Chandru
Reply With Quote
  #4 (permalink)  
Old December 22nd, 2006, 10:37 PM
Friend of Wrox
 
Join Date: Aug 2004
Location: Orange County, CA, USA.
Posts: 385
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I think everyone would prefer just going strait to bcp/bulk insert. Problem is if you have errors in your source data it simply fails and doesn't allow you to write code to fix it. In this very simple example you probably won't have any problems. But when things get more complex and you have bad data coming in BCP/Bulk insert is basically a pass/fail process if you get bad data for one row the whole load could fail. Hard to get bad data in your super simple example here but as complexity grows the easiest solution isn't always the best solution.

Reply With Quote
  #5 (permalink)  
Old December 23rd, 2006, 10:18 AM
Friend of Wrox
Points: 1,536, Level: 15
Points: 1,536, Level: 15 Points: 1,536, Level: 15 Points: 1,536, Level: 15
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2006
Location: , MI, USA.
Posts: 475
Thanks: 0
Thanked 9 Times in 9 Posts
Default

Quote:
quote:Originally posted by carumuga
 Thanx for the reply.
It would be better to provide some eg in BCP/Bulk Insert so that i can work around the said problem.
Creating a staging table and then splitting is a tedious job, so i would prefer to go for BCP/Bulk Insert.
Then, because it is a fixed field format, you MUST create a format file whether you use BCP or BULK INSERT. Please refer to "bcp utility, format files, using format files" in Books Online... there's a bit too much than to write here. It's not difficult, just "bulky".

--Jeff Moden
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
SQL Server 2000 DTS Excel Import Error Tglover SQL Server DTS 0 June 22nd, 2007 12:27 PM
Import Data In MS SQL SERVER 2000 The Beginner Classic ASP Basics 1 August 14th, 2006 04:59 PM
Import delimited flat file into SQL Server 2000 DevCsharp C# 1 April 27th, 2005 11:52 PM
Import XML and its attribute into SQL server 2000 khautinh C# 0 April 13th, 2005 09:57 AM
Help me on Fixed Field Length data files hossrad SQL Server DTS 3 January 29th, 2005 07:50 PM



All times are GMT -4. The time now is 08:52 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.