Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server 2008 r2 SSIS将一个平面文件源3列合并为2个union all_Sql Server 2008 R2_Ssis - Fatal编程技术网

Sql server 2008 r2 SSIS将一个平面文件源3列合并为2个union all

Sql server 2008 r2 SSIS将一个平面文件源3列合并为2个union all,sql-server-2008-r2,ssis,Sql Server 2008 R2,Ssis,我有一个带分隔符的平面文件,它有3列: NEW # DETAIL OLD # ------ ------ ------ 111111 AAAA 123456 222222 BBBB 333333 CCCC 987654 我需要我的输出是 # DETAIL ------ ------ 111111 AAAA 222222 BBBB 333333 CCCC 1234

我有一个带分隔符的平面文件,它有3列:

NEW #     DETAIL    OLD #
------    ------    ------
111111    AAAA      123456
222222    BBBB
333333    CCCC      987654
我需要我的输出是

#         DETAIL   
------    ------
111111    AAAA      
222222    BBBB
333333    CCCC      
123456    AAAA
987654    CCCC
我需要忽略旧列中的空值


我不确定实现这一目标的最佳方式。如果您有多个源,则“全部联合”和/或“合并”似乎有效

一般的概念是,你会想要。杰森·斯特拉特在他的博客上写了一篇很好的文章

基本思想是,您希望保留DETAIL列,并让其他两个列流入其中。Unpivot是规范化数据的本机操作

来源 我使用了一个查询,因为它可以更快地启动,我在一行中添加了一个显式的空值

SELECT
*
FROM
(
    VALUES
    ('111111','AAAA','123456')
,   ('222222','BBBB','')
,   ('333333','CCCC','987654')
,   ('444444','DDDD',NULL)
) D([NEW #], [DETAIL],[OLD #]); 
揭穿 该操作将取消打印数据。这将消除空值,但保留空字符串。这可能是你想要的结果,也可能不是

后果 此时,您可以看到我们有空字符串行。你可以用两种方法来解决这个问题,我让你选择你的方法

上游-将空字符串清除为NULL 下游-使用条件拆分删除具有空数值的行 Biml 商业智能标记语言Biml描述了商业智能平台。在这里,我们将用它来描述ETL,是VisualStudio/BIDS/SSDT的免费附加组件,解决了它的许多缺点。具体来说,我们将使用将描述ETL的Biml文件转换为SSIS包的功能。这还有一个额外的好处,即为您提供了一种机制,使您能够准确地生成我所描述的解决方案,而不是单击许多冗长的对话框

<Biml xmlns="http://schemas.varigence.com/biml.xsd">
    <Connections>
        <OleDbConnection ConnectionString="Provider=SQLNCLI11;Data Source=localhost\dev2014;Integrated Security=SSPI;Initial Catalog=tempdb" Name="CM_OLE" />
    </Connections>
    <Packages>
        <Package 
            ConstraintMode="Linear" 
            Name="so_25670727">
            <Tasks>
                <Dataflow Name="DFT Combine all">
                    <Transformations>
                        <!--
                        Generate some source data. Added a row with an explicit NULL
                        as no real testing is done unless we have to deal with NULLs
                        -->
                        <OleDbSource ConnectionName="CM_OLE" Name="OLE_SRC Query">
                            <DirectInput>
SELECT
*
FROM
(
    VALUES
    ('111111','AAAA','123456')
,   ('222222','BBBB','')
,   ('333333','CCCC','987654')
,   ('444444','DDDD',NULL)
) D([NEW #], [DETAIL],[OLD #]);                                
                            </DirectInput>
                        </OleDbSource>
                        <!--
                        Unpivot the data. Combine NEW # and OLD # into a single column called Number.
                        A "Pivot Key Value" column will also be generated that identifies where the value came
                        from.
                        -->
                        <Unpivot Name="UP Detail">
                            <Columns>
                                <Column SourceColumn="DETAIL" TargetColumn="DETAIL"/>
                                <Column SourceColumn="NEW #" TargetColumn="Number" PivotKeyValue="NEW #"/>
                                <Column SourceColumn="OLD #" TargetColumn="Number" PivotKeyValue="OLD #"/>
                            </Columns>
                        </Unpivot>
                        <!--
                        Put something here so we can attach a data viewer
                        Notice, the NULL does not show in the output but the empty string does.
                        Depending on your tolerance, you will want to either
                        * Upstream - scrub empty strings to NULL for elimination 
                        * Upstream - convert NULL to empty string for preservation
                        * Downstream - use a Conditional Split to remove the rows with empty Number columns
                        -->
                        <DerivedColumns Name="DER DataViewer">
                        </DerivedColumns>
                    </Transformations>
                </Dataflow>
            </Tasks>
        </Package>
    </Packages>
</Biml>