dbTalk Databases Forums  

flat file import in SSIS

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


Discuss flat file import in SSIS in the microsoft.public.sqlserver.dts forum.



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

Default flat file import in SSIS - 08-22-2006 , 12:47 AM






I have a flat file with row delimiter <cr> & <lf> and column delimiter <tab>.
This file has certain rows less columns than other rows. The rows which have
less columns have early termination with <cr> & <lf>. When I parsed this
file, I found SQL is not inserting missing column delmiters and show the
data, instead the data is messed up because of less column delimiters in
certain rows. Whereas this works perfectly fine with sql server 2000 dts. Is
this a bug in SSIS or this is the new behavior? Does SSIS provide a way to
resolve this scenario?

Thanks
Ramani

Reply With Quote
  #2  
Old   
Nico Verheire
 
Posts: n/a

Default RE: flat file import in SSIS - 08-31-2006 , 10:35 AM






I experienced the same problem...
DTS imports NULL values for the missing columns, whereas SSIS sees the CRLF
chars just as the beginning of the next (missing) field and totally screws
the columns.

I think there is no solution is SSIS.

My workaround involves "fixing" the flatfile before importing it, giving
each row all the needed columns. I implemented this in a script task. See
code:

Public Sub Main()
'
' Add your code here
'
Dim varFieldCount As Integer =
Integer.Parse(Dts.Variables("constInputFieldCount" ).Value.ToString)
Dim varFileName As String =
Dts.Variables("varFileName").Value.ToString
Dim varFileNameFIXED As String =
Dts.Variables("varFileNameFIXED").Value.ToString

Dim inputStream As New System.IO.StreamReader(varFileName)
Dim outputStream As New System.IO.StreamWriter(varFileNameFIXED)
Dim origLine As String
' separator
Dim spl(0) As String
spl(0) = """;"""

Dim tempFieldCount As Integer

Do
origLine = inputStream.ReadLine
If Not origLine Is Nothing Then
tempFieldCount = origLine.Split(spl,
StringSplitOptions.None).Length
For iCounter As Integer = 1 To (varFieldCount -
tempFieldCount)
origLine &= ";"""""
Next
outputStream.WriteLine(origLine)
End If
Loop Until origLine Is Nothing
inputStream.Close()
outputStream.Close()

' varFileTimestamp
Dts.Variables("varFileTimestamp").Value =
System.IO.File.GetLastWriteTime(varFileName)

Dts.TaskResult = Dts.Results.Success
End Sub

Notice that my flatfile is ;-separated, and is textqualified (") on all
fields. Having no textqualifiers at all is also simple. When it's not the
case on all fields, the logic could get a little trickier... :-)
In this case, I just count occurences of ";"
For every column that is missing, I added ;""

Hope this helps
Nico Verheire




"ramani viswanathan" wrote:

Quote:
I have a flat file with row delimiter <cr> & <lf> and column delimiter <tab>.
This file has certain rows less columns than other rows. The rows which have
less columns have early termination with <cr> & <lf>. When I parsed this
file, I found SQL is not inserting missing column delmiters and show the
data, instead the data is messed up because of less column delimiters in
certain rows. Whereas this works perfectly fine with sql server 2000 dts. Is
this a bug in SSIS or this is the new behavior? Does SSIS provide a way to
resolve this scenario?

Thanks
Ramani

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.