dbTalk Databases Forums  

fixed width file problem

microsoft.public.sqlserver.dts microsoft.public.sqlserver.dts


Discuss fixed width file problem in the microsoft.public.sqlserver.dts forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
scottrm
 
Posts: n/a

Default fixed width file problem - 11-11-2005 , 07:08 AM






I am importing a text file delimited in fixed width format. (Sql Server 2000)
Even though I have set the width of all the fields correctly in the dts
wizard when I run the import, for some records I seem to get the start of
the next record appended onto the end of the record and the next record is
skipped entirely. I think the problem is because the last field in the text
file is text of variable length and if the length is less than the maximum
the DTS seems to take part of the next line to make up the space. Any
solutions?
--
Scott

Reply With Quote
  #2  
Old   
Allan Mitchell
 
Posts: n/a

Default Re: fixed width file problem - 11-12-2005 , 04:05 AM






You can try padding the columns

Have a look at this

http://www.databasejournal.com/featu...le.php/1462341

Allan

"scottrm" <scottrm (AT) newsgroup (DOT) nospam> wrote


Quote:
I am importing a text file delimited in fixed width format. (Sql Server
2000)
Even though I have set the width of all the fields correctly in the dts
wizard when I run the import, for some records I seem to get the start
of
the next record appended onto the end of the record and the next record
is
skipped entirely. I think the problem is because the last field in the
text
file is text of variable length and if the length is less than the
maximum
the DTS seems to take part of the next line to make up the space. Any
solutions?
--
Scott


Reply With Quote
  #3  
Old   
scottrm
 
Posts: n/a

Default Re: fixed width file problem - 11-12-2005 , 11:02 AM



Thanks for the reply but it does seem a bit of a messy workaround. Although
if the limitations of DTS mean it has to be done...

Any other ideas would be appreciated.
--
Scott


"Allan Mitchell" wrote:

Quote:
You can try padding the columns

Have a look at this

http://www.databasejournal.com/featu...le.php/1462341

Allan

"scottrm" <scottrm (AT) newsgroup (DOT) nospam> wrote in message
news:AB7F09CF-83F9-4614-B4A3-E2BE86598B27 (AT) microsoft (DOT) com:

I am importing a text file delimited in fixed width format. (Sql Server
2000)
Even though I have set the width of all the fields correctly in the dts
wizard when I run the import, for some records I seem to get the start
of
the next record appended onto the end of the record and the next record
is
skipped entirely. I think the problem is because the last field in the
text
file is text of variable length and if the length is less than the
maximum
the DTS seems to take part of the next line to make up the space. Any
solutions?
--
Scott



Reply With Quote
  #4  
Old   
Michael Cheng [MSFT]
 
Posts: n/a

Default RE: fixed width file problem - 11-14-2005 , 06:33 AM



Hi Scott,

Since this a by design behavior as BOL states that when you import fixed
width files via DTS, the rows must have the same number of characters.



You may consider the workarounds:



1. Use Jet/MS Access to import: The Jet database engine has special code
which will handle the situation mentioned above and import the file
correctly. Then you can use DTS against the Access db to import to SQL
Server.



2. Add an Active X Script to the package which reads the original text
file, and spits it back out as a DELIMITED text file, then use then use DTS
to point to the new text file. This ActiveX task should be the first task
in the package


The following sample script imports a file called test.txt, reads through
it's four fields per record, and then spits it out to a delimited text file
named testfile.txt. You'll need to have a schema.ini file setup for the
code to be able to read the orginal test.txt file correctly, and the
schema.ini file must be in the same folder as the file we're importing. For
more details on this file see the orginal case, or use the following link:



http://msdn.microsoft.com/library/bo...c8_body_34.htm



Here's what the schema.ini for text.txt would look like



[test.txt]

ColNameHeader=False

format=FixedLength

Col1=MyFlag integer Width 1

Col2=Field1 Text Width 5

Col3=Field2 Text Width 5

Col4=Field3 Text Width 4





Function Main()



Dim strBuild

Dim fso, tf

Set fso = CreateObject("Scripting.FileSystemObject")

Set tf = fso.CreateTextFile("c:\testfile.txt", True)

Set conn = CreateObject("ADODB.Connection")

Set rs = CreateObject("ADODB.Recordset")



conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\;Extended
Properties=Text;"

rs.Open "Select * from test.txt", conn



rs.MoveFirst

Do While Not rs.EOF

strBuild = Trim(rs(0)) & "," & Trim(rs(1)) & "," & Trim(rs(2)) & ","
&
Trim(rs(3))

tf.WriteLine (strBuild)

rs.MoveNext

Loop



tf.Close

Main = DTSTaskExecResult_Success

End Function


Thank you for your patience and cooperation. If you have any questions or
concerns, don't hesitate to let me know. We are always here to be of
assistance!


Sincerely yours,

Michael Cheng
Microsoft Online Partner Support

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
================================================== ===
This posting is provided "AS IS" with no warranties, and confers no rights.


Reply With Quote
Reply




Thread Tools
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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.