我的sql服务器中有一个表客户。
列
我们每月从分销商那里收到客户档案。 因此有时他们使用错误的结构发送文件。.例如,可能缺少gstin或缺少dl_number或gstin代替了dl_number且dl_number代替了tel ...基本上,列可以拆分。
当我们使用SSIS上传这些平面文件时,会出现错误..并且如果结构不正确,数据也不会上传到服务器上。
如果列丢失或列放错了,我想用空数据上传那些数据。
答案 0 :(得分:2)
根据您的评论,您正在处理平面文件。要解决此问题,您必须将所有列都读取为一列,并在运行中检索结构。
Dataflow task
Dataflow task
内添加平面文件源,脚本组件和OLEDB目标。在脚本内部编写以下代码。
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
将输出列映射到OLEDB目标