Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Import/Export (DTS) and Replication (2000)
 Fixed Width format files

Author  Topic 

Beachsandintoes
Starting Member

15 Posts

Posted - 2005-09-29 : 12:36:27
Hi,

How do we skip fixed-width columns using a format file? For example, we only need to import first and last names from the sample text file. Note the forum tool strips out extra spaces. The actual file starts a new column every 10 characters(First Name is 1 - 10, Middle Name is 11 - 20, Last Name is 21 - 30) :

FIRST MIDDLE LAST
DAVID LEE ROTH
ALFRED E NEWMAN
EDGAR ALLEN POE



We could import all three columns using a format file like:
8.0
3
1 SQLCHAR 0 10 "" 1 First_Name
2 SQLCHAR 0 10 "" 2 Middle_Mame
3 SQLCHAR 0 10 "\r\n" 3 Last_Name



But, we need somethng more like:
8.0
3
1 SQLCHAR 0 10 "" 1 First_Name
3 SQLCHAR 0 10 "\r\n" 3 Last_Name


Also, what would we do if we only needed the first two columns? In this caswe, we wouldn't be able to specify the row terminator.
8.0
3
1 SQLCHAR 0 10 "" 1 First_Name
2 SQLCHAR 0 10 "" 2 Middle_Mame



As always, thank you for your time and insights.

- Beach

X002548
Not Just a Number

15586 Posts

Posted - 2005-09-29 : 13:08:15
Don't you need collation?

8.0
3
1 SQLCHAR 0 10 "" 1 First_Name
2 SQLCHAR 0 10 "" 0 Middle_Mame
3 SQLCHAR 0 10 "\r\n" 3 Last_Name

Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx
Go to Top of Page

Beachsandintoes
Starting Member

15 Posts

Posted - 2005-09-29 : 14:05:40
Heh heh, yes. So here it is the collation friendly version.

8.0
3
1 SQLCHAR 0 10 "" 1 First_Name SQL_Latin1_General_CP1_CI_AS
2 SQLCHAR 0 10 "" 2 Middle_Mame SQL_Latin1_General_CP1_CI_AS
3 SQLCHAR 0 10 "\r\n" 3 Last_Name SQL_Latin1_General_CP1_CI_AS

Please no e-mails from the Collation Coalition telling me about how I was being insensitive to the needs of Collation.

- Beach
Go to Top of Page
   

- Advertisement -