SSIS结果集,Foreachloop和变量 [英] SSIS Result set, Foreachloop and Variable

查看:211
本文介绍了SSIS结果集,Foreachloop和变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一个问题,我不知道这是否有可能.

I'm having an issue and I don't know if this is possible to do.

我有一个简单的SQL任务.

I have a simple SQL task.

SELECT Name, email FROM table_name

使用结果集,我试图将其传递给变量,并在带有foreach循环的电子邮件任务上使用它,但是我没有运气使它起作用.如果我只做一栏,那就行得通.我的问题是多列.

Using a result set, I'm trying to pass it to a variable and use it on a email task with a foreach loop but i having no luck getting this to work. If I do just one column, it works fine. My issue is multiple columns.

非常感谢您的帮助.

推荐答案

我想出了自己的问题.如果有人遇到同样的问题,我将在此处添加.

I figured out my own question. I will add it here in case someone else have the same issue.

  1. 在SQL查询上,第一列应该是您的关键结果.例如我的是电子邮件.

  1. On the SQL query the first column should be your key result. for example mine was the email.

常规下的 SQL任务中,将结果集设置为全结果休止符"

In the SQL Task under General, set Resultset to "Full Result rest"

结果集下的 SQL任务中,将变量名称设置为"0",为电子邮件创建一个变量作为对象"数据类型列,然后单击确定以保存并退出.示例:email_Ob

In the SQL Task under Result Set, set variable with "0" as result name, create a variable as "Object" data type for the email column and click ok to save and exit. Example: email_Ob

转到 variable 窗口,为其他列创建更多变量作为Object,由于我将其用于电子邮件任务,因此需要将Object转换为String,因此需要为每个变量创建另一个变量作为字符串

By going to the variable window, create more variable for the other columns as Object and since I'm using this for email task I need to convert from Object to String, so I need to create another variable as string for each one

示例:

       **Variable Name**       **Datatype**
           email_Ob                Object
           Name_Ob                 Object
           email_St                String
           Name_St                 String

  • Foreach循环任务集合下,更改以下内容:

  • Foreach Loop task Under Collection change the following:

    枚举器:Foreach ADO枚举器

    Enumerator: Foreach ADO Enomator

    ADO对象源变量:选择键变量(email_Ob)

    ADO object Source variable: Select the key variable (email_Ob)

    在第一张表中选择

    Foreach循环任务添加具有 String 数据类型的变量,其顺序与SQL查询中的顺序相同.单击确定"保存并退出.

    Foreach Loop task under Variable Mappings add the variable with String data type the same order as on your SQL query. Click OK to save and exit.

    现在,您可以在 Foreach循环中添加电子邮件任务,并将这些String变量用作电子邮件的一部分,也可以将其用于其他任何任务.

    Now you can add the Email Task inside Foreach Loop and use those String variable as part of the email or you can use it for any other task.

    希望获得帮助,如果您有任何疑问,请随时提出.这样,我可以根据需要添加更多列.

    Hope this help and if you have any questions feel free to ask. Doing this way, I was able to add more columns as need it.

    这篇关于SSIS结果集,Foreachloop和变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆