how to check column structure in ssis?

Deadly 提交于 2019-11-28 14:01:09

Solution

Based on your comment, you are handling with flat files. To solve this problem, you have to read all columns as one column and retrieve the structure on the go.

Details

  1. First add a Flat file connection manager.
  2. In the flat file connection manager, go to the Advanced Tab, remove all columns and keep only one column (Column0).
  3. Change the column type to DT_WSTR and the length to 4000.
  4. Add a Dataflow task
  5. Inside the Dataflow task add a Flat File source, a script component and an OLEDB destination.
  6. Open the script component, go to Input/Output Tab and and add 8 output columns (Distributer_Code,Cust_code,cust_name,cust_add,zip,tel,dl_number,gstin)
  7. Change the script language to Visual Basic.
  8. Inside the script write the following code.

    Dim Distributer_Code as integer = -1
    Dim Cust_code as integer = -1
    Dim cust_name as integer = -1
    Dim cust_add as integer = -1
    Dim zip as integer = -1
    Dim tel as integer = -1
    Dim dl_number as integer = -1
    Dim gstin as integer = -1
    Dim intRowIndex as integer = 0
    
    Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Input0Buffer)
    
        If intRowIndex = 0 then
    
            Dim strfields() as string = Row.Column0.split(CChar("|"))
            Dim idx as integer = 0
    
            For idx = 0 To strFields.length - 1
    
                Select case str
    
                Case "Distributer_Code"
                    Distributer_Code = idx  
                Case "Cust_code"
                    Cust_code = idx 
                Case "cust_name"
                    cust_name = idx 
                Case "cust_add"
                    cust_add = idx  
                Case "zip"
                    zip = idx   
                Case "tel"
                    tel = idx   
                Case "dl_number"
                    dl_number = idx 
                Case "gstin"
                    gstin = idx 
    
                End Select
    
            Next
    
        Else
    
            Dim strfields() as string = Row.Column0.split(CChar("|"))
    
            If Distributer_Code > -1 Then Row.DistributerCode = strfields(Distributer_Code)
            If Cust_code > -1 Then Row.Custcode = strfields(Cust_code)
            If cust_name > -1 Then Row.custname = strfields(cust_name)
            If cust_add > -1 Then Row.custadd = strfields(cust_add)
            If zip > -1 Then Row.zip = strfields(zip)
            If tel > -1 Then Row.tel = strfields(tel)
            If dl_number > -1 Then Row.dlnumber = strfields(dl_number)
            If gstin > -1 Then Row.gstin = strfields(gstin)
    
        End If
    
    
        intRowIndex += 1
    
    End Sub
    
  9. Map the output columns to the OLEDB Destination

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!