如何检查ssis中的列结构?

how to check column structure in ssis?

我的 sql 服务器中有一个 table 客户。

  1. Distributer_Code
  2. Cust_code
  3. cust_name
  4. cust_add
  5. zip
  6. 电话
  7. dl_number
  8. gstin

我们每月从经销商那里收到客户文件。 所以有时他们会发送带有错误结构的文件.. 就像 gstin 丢失或 dl_number 丢失或 gstin 代替 dl_number 和 dl_number 代替电话...基本上, 列可以拆分..

当我们使用 SSIS 上传这些平面文件时出现错误..如果结构错误,则数据不会上传到服务器。

如果列缺失或列错位,我想上传那些包含空数据的数据。

解决方案

根据您的评论,您正在处理平面文件。要解决此问题,您必须将所有列作为一列读取并随时检索结构。

详情

  1. 首先添加平面文件连接管理器。
  2. 在平面文件连接管理器中,转到“高级”选项卡,删除所有列并仅保留一列(Column0)
  3. 将列类型更改为 DT_WSTR,将长度更改为 4000。
  4. 添加一个Dataflow task
  5. Dataflow task 中添加平面文件源、脚本组件和 OLEDB 目标。
  6. 打开脚本组件,转到 Input/Output 选项卡并添加 8 个输出列 (Distributer_Code,Cust_code,cust_name,cust_add,zip,tel,dl_number,gstin)
  7. 将脚本语言更改为 Visual Basic。
  8. 在脚本中写入以下代码。

    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. 将输出列映射到 OLEDB 目标