简体   繁体   English

在SSIS或SQL命令中合并多个表

[英]Merge multiple tables in SSIS or SQL command

I'm facing a problem with fetching data from multiple sources. 我在从多个来源获取数据时遇到问题。 It would be great if you can provide your ideas to design the SQL query. 如果您可以提供自己的想法来设计SQL查询,那就太好了。 I have to take data from two tables and INSERT it into a third table. 我从两个表中获取数据, INSERT成第三个表。

INPUT 输入

TABLE 1
- TaskOrderNumer
- MemberID

TABLE 2
- ReferenceID
- MemberID

OUTPUT 输出值

TABLE 3
- TaskRefID
- PatID

My input table has TaskOrderNumber and MemberID . 我的输入表具有TaskOrderNumberMemberID Right now I'm joining TABLE1 and TABLE2 based on MemberID . 现在,我将基于MemberID加入TABLE1TABLE2 I'm getting the corresponding ReferenceID from TABLE2 and mapping it into PatID of TABLE3 . 我得到相应的ReferenceIDTABLE2并将其映射到PatIDTABLE3 The TaskOrder Number in TABLE1 = TaskRefID in TABLE3 . TaskOrder数量TABLE1 = TaskRefIDTABLE3

I'm currently doing this using SSIS components. 我目前正在使用SSIS组件进行此操作。 I want to make sure that the correct data is MERGED. 我想确保正确的数据已合并。 I'm not able to map the TaskOrderNumber to TaskRefID . 我无法将TaskOrderNumber映射到TaskRefID Can you please help me design the solution. 您能帮我设计解决方案吗?

在此处输入图片说明

You can simply query the information you are trying to display. 您可以简单地查询您要显示的信息。 I am not sure I would even bother with SSIS here unless your sources aren't SQL. 除非您的来源不是SQL,否则我不确定在这里甚至不会打扰SSIS。

select t1.TaskOrderID as TaskRefID
   ,t2.ReferenceID as PatID
into Table3 --Added this as edit.
from Table1 t1
join Table2 t2 on t1.MemberID=t2.MemberID

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM