在SSIS中比较两个源并更新sql server表?
我有 excel 源和 sql server 表。
Excel源列是
Mno Price1 Price2
111 10 20
222 30 25
333 40 30
444 34 09
555 23 abc
Sql服务器表
产品表名称
PId Mno Sprice BPrice
1 111 3 50
2 222 14 23
3 444 32 34
4 555 43 45
5 666 21 67
我想将excel源Mno(型号)与sql服务器产品表Mno(型号)进行比较,如果相同我想更新Sql服务器产品表SPrice和Bprice。
请告诉我我想要执行哪些步骤?
我也想验证该 Excel 工作表,因为在 Excel Price2 列中有字符串值,
如果它是字符串值,我想发送哪些行数据错误的邮件。
我是 SSIS 新手,所以请给我详细信息。
I have excel source and sql server table .
Excel Source column is
Mno Price1 Price2
111 10 20
222 30 25
333 40 30
444 34 09
555 23 abc
Sql server Table
Product table name
PId Mno Sprice BPrice
1 111 3 50
2 222 14 23
3 444 32 34
4 555 43 45
5 666 21 67
I want to compare excel source Mno(Model number) with sql server Product table Mno (Model number), and if it is same i want to update Sql server Product table SPrice and Bprice.
Please tell me what are the steps i want to do?
I want to validate that excel sheet also, because in excel Price2 column have string values
if it's string value i want to send mail which row data are wrong.
I am new for SSIS so please give me details.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
读取源中的新数据,使用查找组件查找现有数据。直接行匹配到用于更新的 oledb 命令,以及用于插入的非匹配的目标(如果您想输入新产品)。
Read your new data in a source, use a lookup component for existing data. Direct row matches to a oledb command for update, and a destination for your non-matches for inserts (if you want to enter new products).
我个人认为最简单的方法是使用数据流将 Excel 文件放入临时表中,并在需要时进行清理。然后,作为控制流中的下一步,有一个执行更新的执行 SQl 任务。或者,如果您需要更新或插入(如果记录是新的),请在执行 SQl 任务中使用 Merge 语句。
Personally I think the simplest way to do this is to use a dataflow to bring the excel file into a staging table and do any clean up if need be. Then as the next step inmteh control flow have an Execute SQl task that does the update. Or if you need either an update or an insert if the record is new, use a Merge statement in the Execute SQl task.
您可以使用具有完整外部联接的合并联接转换(请记住在将数据集输入到合并联接转换之前对数据集进行排序),然后将输出转到条件拆分转换。条件拆分转换可以确定是否需要更新、插入或删除行,并将流程引导到适当的转换来执行此操作。
这超出了我的想象,可能有一个更简单的转换。我已经快一年没有机会使用 SSIS 了,所以我可能有点生疏了。
You can use a Merge Join Transformation with a full outer join (remember to sort your datasets before they input to the Merge Join Transformation), then have the output go to a Conditional Split Transformation. The Conditional Split Transformation can determine whether or not a row needs to be updated, inserted, or deleted and direct the flow to the appropriate transform to do that.
This was off the top of my head, and there may be a simpler transform for this. I haven't had the opportunity to work with SSIS in almost a year, so I might be getting a bit rusty.