SSIS:组合两个表中的字段

时间:2014-03-11 10:37:01

标签: sql sql-server tsql ssis sql-server-2012

我有两个关于员工成员的源表:招聘和培训。我需要将它们组合成一个表。

Recruitment table: [UniqueID], [SupplierName], RecruitmentDate, RecruitmentField1, RecruitmentField2, RecruitmentField3, Comments

Training table: [UniqueID], [Supplier], TrainingDate, TrainingField1, TrainingField2, TrainingField 3, TrainingField4, TrainingField5, Comments. 

我想最终得到一个包含以下字段的表(称为SupplyRecruitment) - using [UniqueID] AND [Supplier] as a join key(个人可以存在于多个供应商,因此需要加入基于UniqueID和供应商的唯一记录)。

UniqueID, 
SupplierName, 
RecruitmentDate, 
RecruitmentField1, 
RecruitmentField2, 
RecruitmentField3, 
RecruitmentComments, 
TrainingDate, 
TrainingField1, 
TrainingField2, 
TrainingField3, 
TrainingField4, 
TrainingField5, 
TrainingComments. 

数据集不是很大(最多12,000行),因此性能不是一个重点。简单和准确是关键。

寻找基于SSIS任务的解决方案(使用SQL 2012)。如果这是不可能的,那么对SQL逻辑的一些帮助将不胜感激。谢谢! :)

1 个答案:

答案 0 :(得分:1)

我不确定在SSIS中这样做的好处是诚实。

select r.UniqueID
    , r.SupplierName
    , r.RecruitmentDate
    , r.RecruitmentField1
    , r.RecruitmentField2
    , r.RecruitmentField3
    , r.RecruitmentComments
    , t.TrainingDate
    , t.TrainingField1
    , t.TrainingField2
    , t.TrainingField3
    , t.TrainingField4
    , t.TrainingField5
    , t.TrainingComments
from dbo.Recruitment r 
      inner join do.Training t on r.UniqueID = t.UniqueID
                                  and r.SupplierName = t.Supplier