如何使用ssis实现以下查询

时间:2016-11-23 15:46:26

标签: ssis etl ssis-2012 ssis-2008 ssis-2005

我们可以讨论如何使用ssis将下面的查询结果加载到目标表中。我知道我们可以在T-sql中使用它,也可以作为OLEDB源查询。但仍然想知道如何实现它,只使用数据流量组件

*/5 * * * * cd /opt/bitnami/apps/zurmo/htdocs/app/protected/commands && ./zurmoc jobManager  user Monitor &> /dev/null
30 4 * * * cd /opt/bitnami/apps/zurmo/htdocs/app/protected/commands && ./zurmoc jobManager  user CurrencyRatesUpdate &> /dev/null
30 2 * * 6 cd /opt/bitnami/apps/zurmo/htdocs/app/protected/commands && ./zurmoc jobManager  user ImportCleanup &> /dev/null
*/30 * * * * cd /opt/bitnami/apps/zurmo/htdocs/app/protected/commands && ./zurmoc jobManager  user AddressGeocodeUpdate &> /dev/null
0 */1 * * * cd /opt/bitnami/apps/zurmo/htdocs/app/protected/commands && ./zurmoc jobManager  user AutoresponderQueueMessagesInOutbox &> /dev/null
0 */1 * * * cd /opt/bitnami/apps/zurmo/htdocs/app/protected/commands && ./zurmoc jobManager  user CampaignGenerateDueCampaignItems &> /dev/null
0 */1 * * 6 cd /opt/bitnami/apps/zurmo/htdocs/app/protected/commands && ./zurmoc jobManager  user CampaignMarkCompleted &> /dev/null
0 */1 * * * cd /opt/bitnami/apps/zurmo/htdocs/app/protected/commands && ./zurmoc jobManager  user CampaignQueueMessagesInOutbox &> /dev/null
0 22 * * * cd /opt/bitnami/apps/zurmo/htdocs/app/protected/commands && ./zurmoc jobManager  user ClearSentNotificationsEmail &> /dev/null
*/5 * * * * cd /opt/bitnami/apps/zurmo/htdocs/app/protected/commands && ./zurmoc jobManager  user EmailArchiving &> /dev/null
*/5 * * * 6 cd /opt/bitnami/apps/zurmo/htdocs/app/protected/commands && ./zurmoc jobManager  user EmailBounce &> /dev/null
*/1 * * * * cd /opt/bitnami/apps/zurmo/htdocs/app/protected/commands && ./zurmoc jobManager  user ProcessOutboundEmail &> /dev/null
0 22 * * * cd /opt/bitnami/apps/zurmo/htdocs/app/protected/commands && ./zurmoc jobManager  user TestOutboundEmail &> /dev/null
5 18 * * 6 cd /opt/bitnami/apps/zurmo/htdocs/app/protected/commands && ./zurmoc jobManager  user DraftEmailTemplateCleanup &> /dev/null
5 18 * * 6 cd /opt/bitnami/apps/zurmo/htdocs/app/protected/commands && ./zurmoc jobManager  user ExportCleanup &> /dev/null
5 18 * * 6 cd /opt/bitnami/apps/zurmo/htdocs/app/protected/commands && ./zurmoc jobManager  user CheckZurmoUpdates &> /dev/null
0 * */1 * * cd /opt/bitnami/apps/zurmo/htdocs/app/protected/commands && ./zurmoc jobManager  user JobLogCleanup &> /dev/null
0 */1 * * 6 cd /opt/bitnami/apps/zurmo/htdocs/app/protected/commands && ./zurmoc jobManager  user UpdateModelsLatestActivityDateTimeByMeeting &> /dev/null
*/15 * * * * cd /opt/bitnami/apps/zurmo/htdocs/app/protected/commands && ./zurmoc jobManager  user ByTimeWorkflowInQueue &> /dev/null
*/15 * * * * cd /opt/bitnami/apps/zurmo/htdocs/app/protected/commands && ./zurmoc jobManager  user WorkflowMessageInQueue &> /dev/null
0 22  * * * cd /opt/bitnami/apps/zurmo/htdocs/app/protected/commands && ./zurmoc jobManager  user WorkflowValidityCheck &> /dev/null
*/10 * * * * cd /opt/bitnami/apps/zurmo/htdocs/app/protected/commands && ./zurmoc jobManager  user ReadPermissionSubscriptionUpdate &> /dev/null
5 18 * * 6 cd /opt/bitnami/apps/zurmo/htdocs/app/protected/commands && ./zurmoc jobManager  user ShortUrlCleanup &> /dev/null
*/5 * * * * cd /opt/bitnami/apps/zurmo/htdocs/app/protected/commands && ./zurmoc jobManager  user SendGridEmailEvents &> /dev/null

1 个答案:

答案 0 :(得分:2)

在我们开始之前,免责声明:

复杂的SELECT查询最好用T-SQL表示。 SSIS最适合用于ETL任务。

现在......开始了。让我们看看我们有什么。该查询有十五个LEFT JOINS嵌套在三个级别上:五个位于顶部,七个位于中间,两个位于底部。整个Peppered是一些CAST()GROUP BY s。所有这些SQL命令都可以使用SSIS组件完成。

  • JOIN =合并加入组件。
  • GROUP BY =聚合组件。
  • CAST =派生列组件。

由于你有这么大的查询,我建议把它分成更小的块。从最里面的连接开始。

    select 
        d.myEvent
        ,myProvider
        ,myproviderrolecode
        ,d.Max_ProvOid
    from (                 
        select  A.myEvent, max(b.oid) as Max_ProvOid
        from alleventitems a
        left outer join ProviderEventItemRole as b  
        on a.oid = b.myeventitem
        group by A.myEvent
    ) as d
    left join (                           
        select  A.myEvent,b.myProvider,b.myproviderrolecode,a.oid as a_oid,b.oid as b_oid
        from alleventitems a
        left outer join ProviderEventItemRole as b  
        on a.oid = b.myeventitem
    ) as e 

将其翻译成SSIS就像这样。

enter image description here

上面,我们将四个表合并为一个。您可以详细了解如何配置合并联接here。对剩余的JOINS重复上述模式并将它们连接在一起,您将把整个查询翻译成SSIS!

现在我们可以看到如何可以完成,请问我们为什么要在SSIS中执行此操作?