Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 22nd, 2006, 01:43 AM
Authorized User
 
Join Date: Dec 2006
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
 
Old December 22nd, 2006, 02:02 AM
Friend of Wrox
 
Join Date: Oct 2006
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
 
Old December 22nd, 2006, 05:21 AM
Authorized User
 
Join Date: Dec 2006
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
 
Old December 22nd, 2006, 10:37 PM
Friend of Wrox
 
Join Date: Aug 2004
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.

 
Old December 23rd, 2006, 10:18 AM
Friend of Wrox
 
Join Date: Oct 2006
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





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





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.