English 中文(简体)
如何利用信息社会首脑会议的文字任务,用多种存储程序来撰写数据?
原标题:How to write data from multiple stored procedures to files using SSIS script task?

我在2008年服务器上建立了SSIS一揽子计划,需要通过一个表格加以整理,该表载有该数据库、产出档案的地点、执行名称以及表格内每个客户信息数据库的数据。 该程序储存了不同的报告,并包含不同领域,这是使目前使用多套SSIS软件进行客户报告的过程自动化所需要的,我想简化整个过程。

制作的成套材料I系列包含一个文字部分,将数据节省到一个可变物体上,每个集装箱通过物体变量将数据储存起来,并将数据节省至个别变量。 然而,由于我目前能够与被捆绑连接的管理人联系,我需要协助完成文字任务,然而,在试图执行所储存的程序时,或许由于数据不是通过观点或表格输出的,文字任务却失败。

我是新来的。 该网络的描述和没有这种知识。 NET,我用下面的read子来接手我目前的立场,用一把 d子取代。

Dim query As String = "Exec " & Dts.Variables("User::RunSP").Value

我利用以下职位来担任目前职务:

利用SSIS 平台任务从多个桌子向不同的平坦文档出口数据

当我执行文字任务时,在<条码>、<>条/代码>和<条码>dblinkion开放时,该书即告失败。 我试图在没有<条码>、一节的情况下就此发表评论,执行书状任务,但一直有误。

问题回答

由于你使用了我作为问题答案提供的例子:。 我以同样的榜样从多个桌子出口数据,以使用SSIS的标本的不同平坦文档,并修改了数据,以管理所储存的程序。

似乎没有任何问题。 确保它与你努力做到的一致。 这个例子使用<编码>SSIS 2005,SQL服务器2008 R2数据库。

www.un.org/Depts/DGACM/index_spanish.htm 循序渐进的过程:

建立三个表格,即dbo。 表sList, dbo.Source1 and dbo.Source2。 用一些抽样数据编制表格。 此外,还建立了两个称为 d的储存程序。 SP1 and dbo. SP2. 下面有文字说明,这些任务是制作表格和储存程序。

CREATE TABLE [dbo].[Source1](
    [Id] [int] IDENTITY(1,1) NOT NULL,
    [ItemNumber] [varchar](20) NOT NULL,
    [ItemName] [varchar](50) NOT NULL,
CONSTRAINT [PK_Source1] PRIMARY KEY CLUSTERED ([Id] ASC)) ON [PRIMARY]
GO

CREATE TABLE [dbo].[Source2](
    [Id] [int] IDENTITY(1,1) NOT NULL,
    [Country] [varchar](20) NOT NULL,
    [StateProvince] [varchar](50) NOT NULL,
CONSTRAINT [PK_Source2] PRIMARY KEY CLUSTERED ([Id] ASC)) ON [PRIMARY]
GO

CREATE TABLE [dbo].[TablesList](
    [Id] [int] IDENTITY(1,1) NOT NULL,
    [SPName] [varchar](50) NOT NULL,
    [FilePath] [varchar](255) NOT NULL,
CONSTRAINT [PK_Tables] PRIMARY KEY CLUSTERED ([Id] ASC)) ON [PRIMARY]
GO

INSERT INTO dbo.TablesList (FilePath, SPName) VALUES 
    ( F:TempItem_Details.txt ,  SP1 ),
    ( F:TempCountry_StateProvince.txt ,  SP2 );
GO

INSERT INTO dbo.Source1 (ItemNumber, ItemName) VALUES 
    ( 34534 ,  Keyboard ),
    ( 24312 ,  Mouse ),
    ( 78555 ,  Monitor );
GO

CREATE PROCEDURE [dbo].[SP1]
AS
BEGIN   
    SET NOCOUNT ON;

    SELECT * FROM dbo.Source1
END
GO

CREATE PROCEDURE [dbo].[SP2]
AS
BEGIN   
    SET NOCOUNT ON;

    SELECT * FROM dbo.Source2
END
GO

下表中的数据将如下表所示。

“Sample

关于SSIS一揽子计划,创建了一个与SQ服务器的链接管理员。

“Connection

关于SSIS一揽子计划,产生了4个变量,即Delimiter,FileName,RunSPSPsList。 此外,还安排了“Executekul”任务、“Foreach Loop”集装箱以及“控制流动”的代号任务,详情如下:

“Variables

没收“Executekou”的任务,以挑选以下两个屏幕显示的储存程序清单。

“Execute

“Execute

如以下两张屏幕所示,将Foreach Loop集装箱通过在变异的SPsList中储存的结晶进行 lo。

“Foreach

“Foreach

在《古典》任务栏目中,在“设计”栏目上点击了VSTA编辑。

Script Task

替换VB。 NET代码如下。 守则颁布后,关闭了联邦航空局编辑,以挽救这些变化。

Imports System
Imports System.Data
Imports System.Data.OleDb
Imports System.IO
Imports System.Math
Imports Microsoft.SqlServer.Dts.Runtime

Public Class ScriptMain

    Public Sub Main()

        Dim varCollection As Variables = Nothing

        Dts.VariableDispenser.LockForRead("User::FileName")
        Dts.VariableDispenser.LockForRead("User::Delimiter")
        Dts.VariableDispenser.LockForRead("User::RunSP")
        Dts.VariableDispenser.GetVariables(varCollection)

        Dim fileName As String = varCollection("User::FileName").Value.ToString()
        Dim query As String = "EXEC " & varCollection("User::RunSP").Value.ToString()
        Dim delimiter As String = varCollection("User::Delimiter").Value.ToString()

        Dim writer As StreamWriter = Nothing
        Dim connection As OleDbConnection = New OleDbConnection(Dts.Connections("Learn2008R2").ConnectionString)
        Dim command As OleDbCommand = Nothing
        Dim reader As OleDbDataReader = Nothing

        Try
            If File.Exists(fileName) Then
                File.Delete(fileName)
            End If

            connection.Open()
            command = New OleDbCommand(query, connection)
            reader = command.ExecuteReader()

            writer = New System.IO.StreamWriter(fileName)

            Dim row As Integer = 0
            Dim header As Integer = 0
            Dim fieldCount As Integer = reader.FieldCount - 1

            If row = 0 Then
                While header <= fieldCount
                    If header <> fieldCount Then
                        writer.Write(reader.GetName(header).ToString() & delimiter)
                    Else
                        writer.WriteLine(reader.GetName(header).ToString())
                    End If
                    header += 1
                End While
            End If

            If reader.HasRows Then
                While reader.Read()
                    Dim counter As Integer = 0
                    While counter <= fieldCount
                        If counter <> fieldCount Then
                            writer.Write(reader(counter).ToString() & delimiter)
                        Else
                            writer.WriteLine(reader(counter).ToString())
                        End If
                        counter += 1
                    End While
                End While
            End If
        Catch ex As Exception
            Throw ex
        Finally
            connection.Close()
            writer.Close()
        End Try

        Dts.TaskResult = Dts.Results.Success

    End Sub

End Class

F:执行一揽子计划之前的夹子内容。 脚本是空的。

“F

成功实施一揽子方案的情况见以下屏幕。

“Success”/

Folder path F:Temp现在使用个人储存程序SP1和SP2提供的数据,在包裹中包含由文字任务产生的两个档案。

“F

Contents of the files are shown in the below screenshots. The file contents are pipe delimited and you can notice the data matches with the table data shown in the earlier screenshot.

“File

“File

Hope that helps.





相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

难以执行 REGEXP_SUBSTR

I m 查询Oracle 10g。 我有两张表格(样本数据见下文)。 i m 试图提取一些领域

SQL Query Shortcuts

What are some cool SQL shorthands that you know of? For example, something I learned today is you can specify to group by an index: SELECT col1, col2 FROM table GROUP BY 2 This will group by col2

PHP array callback functions for cleaning output

I have an array of output from a database. I am wondering what the cleanest way to filter the values is example array Array ( [0] => Array ( [title] => title 1 ...

OracleParameter and DBNull.Value

we have a table in an Oracle Database which contains a column with the type Char(3 Byte). Now we use a parameterized sql to select some rows with a DBNull.Value and it doesn t work: OracleCommand ...

Running numbers in SQL

I have a SQL-statement like this: SELECT name FROM users WHERE deleted = 0; How can i create a result set with a running number in the first row? So the result would look like this: 1 Name_1 2 ...

How to get SQL queries for each user where env is production

I’m developing an application dedicated to generate statistical reports, I would like that user after saving their stat report they save sql queries too. To do that I wrote the following module: ...

热门标签