[转]SSIS Recordset Destination
本文转自:http://www.sqlis.com/sqlis/post/Shredding-a-Recordset.aspx
Doing what to a recordset?
Shredding a recordset in this instance means that we are going to show you how to take a recordset produced in your SSIS package, loop over the rows in that recordset, break apart the columns and do something with them. This is really useful when you want to preform an action on a row of data for every row of data just like we are going to do here. Sure we could use an ExecuteSQL task to get the recordset as well but that does limit our choices of source data whereas doing it in the pipeline does not. Something useful we hope.
Retrieving the Recordset
There are a couple of things that we are going to have to setup first though
The Variables
This task requires four variables. It needs one to hold the recordset and 3 to hold the column values when we shred the recordset. Let's configure those now. In control flow we have a menu titled SSIS and if we drop that down we see Variables as one of the menu choices. Here is how the variables look after completion
The Connections
For this package we are going to need two connections. One for the source data and one for the SMTP server with which we are going to send our mails.
To set up an OLE DB Connection Manager we will right click in the Connection Manager tray at the bottom of our package and choose New OLE DB Connection
We click New and configure as seen in the graphic.
Click OK after doing that and let's create the SMTP connection manager. Same drill as before, right click in the Connection Manager tray only this time we choose New Connection. That brings us to the following screen where we now choose the SMTP Connection as shown.
We then have to configure the connection manager and luckily it is one of, if not the, most easy to set up of all.
If you look in the Connection Manager tray now you should see something very similar to the following
The DataFlow Task
This task in this example is about one thing and that is getting the data we want into a variable so we can use it later in the package. We are going to need to fill our recordset with something so we will need to define a statement that retrieves our rows. Imagine we have sales people who take contact details from potential customers. They must contact those people within 30 days and update our CRM system. If they do not then we want to let them know through eMail that they are overdue.
So now we have something to put into a recordset let's build the means by which we can get the data. Begin by adding a Data Flow task to the Control Flow. Double click on the task to enter the Data Flow section of our package. Now drag from the toolbox onto the design surface the following:
- An OLE DB Source
- A Recordset Destination
The first thing we are going to do is configure the OLE DB Source so we double click on it to open up its editor
In here we are going to specify the connection manager built earlier, an Access Mode of SQL Command and a SQL command text. The graphic above shows this completed
If we look to the left of this editor we can see a columns branch on the tree underneath the connection manager branch. This is where we need to tell the source what columns from our statement we want to flow down the pipeline so we click on that now and request that all columns be sent.
Now we need to configure the recordset destination. Before we do that we drag the green connection coming from the OLE DB source and simply attach it to the recordset destination. This will give the destination the ability to know what to expect in terms of structure. After attaching the connector we double click on the recordset destination.
The thing to see on this page is the VariableName property to which we give the name of the variable in which we want to store the recordset (rsDetails).
Just like we did on the source we need to configure some columns and we do that by clicking on the Input Columns tab. We want to write all columns to the destination so we select all the available columns.
When we now come out of the destination editor our Data Flow looks like this.
Breaking It Apart
We have seperated this part of setup because it is logically distinct from the previous phase. This is where we are going to grab the recordset, break it apart and use the values we get from breaking it apart and do something with them.
The ForEach Container
The ForEach Loop container allows us to loop over a collection of objects. We can, using this container, loop over a number of inbuilt collections but in this article we are in interested in only one of the collections, the ADO Enumerator. When the enumerator loops over the collection it returns at most one instance of the collection on each iteration. That object needs to be passed out to the tasks inside the container and we do that through a variable. In this article we use the variable User::rsDetails. We drop a ForEach Loop container onto designer from the toolbox. After double clicking on it we choose from the tree on the left Collection. The following graphic shows our collection chosen and variable assigned.
So what happens then? Well on each iteration of the loop a row from the recordset is assigned to the variable with in our case three columns. We now need to Shred it. We now click on the Variable Mappings item in the tree. The following graphic shows our variables configured to accept the columns in the recordset.
What''s happening here is that the variables on the left that we configured earlier are being assigned to the column indexes, on the right, in the recordset and they are zero based. We have no expressions to configure so that''s it for this task. Right so we have our columns in the row mapped to variables and we need to do something with them. That comes now with the Send Mail Task
The Send Mail Task With Expressions
This does as the name suggests and for us this is the way that we are going to communicate to our employees that they have not followed up on their leads. Remember the SMTP Connection Manager we configured earlier well this where we are going to use it. Drop a Send Mail task onto the designer and place it inside the ForEach Loop container.
We double click on the task and after configuration it looks now like this.
We haven't configured all the properties we need because we are going to use property expressions to do that in a moment so we click on Expressions in the tree on the left.
As you can from the graphic above there are ellipses to the right and we need to click on them now. The window we now see is where we will choose a property on the left hand side of the window and then assign an expression on the right. Again we see here ellipses and this will take us to a great expression editor for the property. The window is shown below.
The thing about property expressions is that they are evaluated at runtime. We can build quite complex expressions to map to our properties. In this article we need three properties to be dynamic and part of the expressions will be the variables we grabbed earlier. The properties we need to configure are:
- Message Source
- ToLine
- Subject
The following three graphics show these properties in the expression editor with their expressions set.
The Message Source
One thing to note about this window is that we have pressed the Evaluate Expression button and as you can see our expression is evaluated and displayed. This gives you an idea of what it ill look like when this happens at runtime
The ToLine
The Subject
Now with all our expressions set the expressions window looks like this
That''s it for expressions so the last thing we need to do is join the green connector from the Data Flow Task onto the Foreach Loop Container and we''re done.
Summary
This article has demonstrated a number of new things in SSIS and we hope you have found it useful. Be sure to let us know if you think the Recordset Enumerator is useful and any interesting uses to which you may put it.
[转]SSIS Recordset Destination的更多相关文章
- SSIS ->> Excel Destination无法接受大于255个字符长度的字符字段(转载)
从下文的链接中找到一些背景,因为Excel会以前8行作为参考,如果某个字段前8行的最长长度没有超过255个字符,就会报错.如果知道某个字段属于描述性字段,而且字段的数据长度很可能超过255个字符长度, ...
- SSIS ->> Excel Destination无法接受大于255个字符长度的字符字段
从下文的链接中找到一些背景,因为Excel会以前8行作为参考,如果某个字段前8行的最长长度没有超过255个字符,就会报错.如果知道某个字段属于描述性字段,而且字段的数据长度很可能超过255个字符长度, ...
- BI之SSIS入门最新版Visual Studio调试技巧
简介 最近公司业务需要用到BI SSIS,SSIS是什么?"SSIS是Microsoft SQL Server Integration Services的简称,是生成高性能数据集成解决方案( ...
- SSIS:控件清单
Control Flow 控制流程 Containers 容器 For Loop Container Foreach Loop Container Sequence Container Core Ta ...
- SSIS Destination 组件使用Fast-Load mode出错
查看一个Package的历史Message 数据,发现 DataFlow Task 经常出错,错误信息的Description是: Description: "While reading c ...
- 微软BI 之SSIS 系列 - 使用 Script Component Destination 和 ADO.NET 解析不规则文件并插入数据
开篇介绍 这一篇文章是 微软BI 之SSIS 系列 - 带有 Header 和 Trailer 的不规则的平面文件输出处理技巧 的续篇,在上篇文章中介绍到了对于这种不规则文件输出的处理方式.比如下图中 ...
- [转]Insert, Update, and Delete Destination table with SSIS
本文转自:http://www.rad.pasfu.com/index.php?/archives/150-Insert,-Update,-and-Delete-Destination-table-w ...
- ssis error at other ssis.pipeline "ole db destination" failed validation and returned validation status
我在修改一个ssis的包,发现这个destination的表被改过了.所以就重建了表.就导致了这个错误. 打开包重新检查下表结构的匹配就好了
- SSIS 处理NULL
不同于SQL Server中NULL表示值是未知的(Unknown Value),没有数据类型,但是,在SSIS中,NULL是有数据类型的,要获取某一个NULL值,必须指定数据类型,例如,变量 Int ...
随机推荐
- 创建数据库表的SQL语句
创建表.视图.索引的sql语句如下: CREAT TABLE (列名,数据类型,约束) create view(创建视图) create index (创建索引) 1.primary key(主键) ...
- 关于自适应屏幕,设置子元素浮动,父div不能包裹子div,子元素中内容溢出的问题。
设置HTML适应不同分辨率的屏幕. 需求结构如下: HTML结构代码如下(只是其中一条): <body> <div class="content">< ...
- IntelliJ IDEA centos安装
安装的时候注意: 不要装一个插件否则无法启动!!!
- LightOJ - 1234
Harmonic Number Time Limit: 3000MS Memory Limit: 32768KB 64bit IO Format: %lld & %llu Descri ...
- LockSupport学习
LockSupport工具类定义了一组的公共静态方法,这些方法提供了最基本的线程阻塞和唤醒功能.Java锁和同步器框架的核心工具类AQS:AbstractQueueSynchronizer,就是通过调 ...
- Java学习笔记(十三)——通过Netbeans开发环境生成oracle数据库中表的对应hibernate映射文件
[前面的话] 身体慢慢已经快好了,感觉真好,哈哈. 这篇文章要通过Hibernate对数据库进行操作,而Netbeans可以直接通过数据库逆向生成对应的映射文件.基础文章,选择性阅读. [步骤] 1. ...
- [Bootstrap]modal弹出框
写在前面 在实际开发中,为了友好,更需要一种美观的弹出框,js原生的alert,很难满足需求.这里推荐一个bootstrap的弹出框. 一个例子 先看效果吧 代码: <!DOCTYPE html ...
- 初探python编码
背景:在实际数据处理中,我们或多或少会接触到中文,如两个dc pack包的diff.使用python对中文数据 处理难免会遇到编码问题. python里面主要考虑三种编码: 1.源文件编码: 如果我们 ...
- hihoCoder #1871 : Heshen's Account Book-字符串暴力模拟 自闭(getline()函数) (ACM-ICPC Asia Beijing Regional Contest 2018 Reproduction B) 2018 ICPC 北京区域赛现场赛B
P2 : Heshen's Account Book Time Limit:1000ms Case Time Limit:1000ms Memory Limit:512MB Description H ...
- 运行hadoop的时候提示物理内存或虚拟内存溢出的解决方案running beyond physical memory或者beyond vitual memory limits
当运行中出现Container is running beyond physical memory这个问题出现主要是因为物理内存不足导致的,在执行mapreduce的时候,每个map和reduce都有 ...