简体   繁体   English

如何在 SSIS 中根据数据来自的表添加列?

[英]How to add a column based on the table which the data come from in SSIS?

I have two source tables:我有两个源表:

  1. Ext_Agreements Ext_Agreements
  2. ABS_Agreements ABS_协议

both have the same columns : "each table have different data this is just an example"两者都有相同的列:“每个表都有不同的数据,这只是一个例子”

                          ID, START_DATE,  END_DATE, 
                          01, 28/02/2021, 04/05/2021
                          02, 11/10/2021, 09/01/2022
                          03, 08/01/2022, 03/05/2022

I want to merge them in one table in the destination Database, while maintaining the information of the type of the agreement by adding a columns "AGREEMENT_TYPE" that contain "Ext" or "ABS" based of the source table of the Agreement.我想将它们合并到目标数据库中的一个表中,同时通过基于协议的源表添加包含“Ext”或“ABS”的列“AGREEMENT_TYPE”来维护协议类型的信息。

the destination table will have :目标表将具有:

                          ID, START_DATE,  END_DATE, AGREEMENT_TYPE
                          01, 28/02/2021, 04/05/2021,  ABS
                          02, 11/10/2021, 09/01/2022,  EXT
                          03, 08/01/2022, 03/05/2022,  ABS

I tried merge and Union All and derived columns, but I didn't succeed.我尝试了合并和联合所有以及派生列,但我没有成功。 thank you谢谢你

How about a UNION ALL in your source.你的源中的 UNION ALL 怎么样。

select ID, START_DATE,  END_DATE, AGREEMENT_TYPE = 'EXT'
from Ext_Agreements
UNION ALL
select ID, START_DATE,  END_DATE, AGREEMENT_TYPE = 'ABS'
from ABS_Agreements

If you want to use SSIS, then...如果你想使用 SSIS,那么...

In data flow.在数据流中。

Create a source based on:根据以下内容创建源:

select ID, START_DATE,  END_DATE --, AGREEMENT_TYPE = 'EXT'
from Ext_Agreements

Add a derived column and add:添加派生列并添加:

AgreementType and set (DT_WSTR, 3) "EXT"

Do the same this for ABS (source and der col).对 ABS(源和 der col)执行相同的操作。

Then put them together in a UnionAll.然后将它们放在一个 UnionAll 中。

暂无
暂无

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

相关问题 使用 SSIS 将数据从具有动态列名的 Excel 移动到表 - Moving the data from Excel which have Dynamic column names to a table using SSIS SSIS:如何将数据从表A传输到表B,然后为每行更新表A标志列 - SSIS: How to transfer data from table A to table B and then update table A flag column for each row SSIS根据另一个表中的行动态选择列名 - SSIS Select column name dynamically based on rows from another table 如何在SSIS中将数据从列更改为行 - How to change the data from column to row in SSIS 在导入到SQL表之前,如何在平面文件源中的SSIS中添加GUID列? - How can I add a GUID column in SSIS from a Flat File source before importing to a SQL Table? 如何从SSIS中的另一个数据源向输出记录集添加其他列? - How to add additional column to an output recordset from another data source in SSIS? SSIS。 如何将具有 nvarchar(max) 类型列的表中的数据保存到原始文件目标 - SSIS. How to save data from a table having column with type nvarchar(max) to raw file destination 如何通过聚合 SSIS 中多列的值来添加新列 - How to add a new column by aggregating values from multiple columns in SSIS 当数据或列当前不在目标表中时,如何将源表中的列添加到目标表中 - How to add a column from source table into destination table when the data or column is currently not in the destination table 如何根据SSIS中数据流任务的比较删除行? - How to delete rows based on comparison from Data Flow Task in an SSIS?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM