如何使用 SSIS 包中的变量值加载新表?

编程入门 行业动态 更新时间:2024-10-27 16:35:50
本文介绍了如何使用 SSIS 包中的变量值加载新表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在 SSIS 包 Var1 和 Var2 中有两个变量.这两个变量都有值.有什么办法可以将这两个变量的值放在新表中吗?例如,在具有 Var1 值的新表 col1 和具有 Var2 值的 col2 中.

i have two variables in a SSIS package Var1 and Var2. Both of these variables have values. is there any way i can put the values of these two variables in a new table? e.g In New table col1 having value of Var1 and col2 having value of Var2.

谢谢

推荐答案

有几种方法可以做到这一点.

There are a couple of ways to do this.

一种是使用派生列任务创建数据流.然后,您可以提取这两个变量并将其发送到 OLE DB 或 SQL Server 目标.

One is to create a data flow with a Derived Column Task. Then you can pull in both variables and send it to a OLE DB or SQL Server Destination.

另一个是使用执行 SQL 任务.其中的技巧部分是正确使用参数.查询将如下所示:

Another is to use a Execute SQL Task. The trick part of this is using the parameters correctly. The query would look like:

IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'dbo.[VarLog]') AND type in (N'U')) DROP TABLE dbo.[VarLog] Create table dbo.varlog ( [var1] [varchar](50) NULL, [var2] [varchar](50) NULL ) Insert into varlog (var1,var2) values(?, ?)

在参数映射屏幕上添加您的两个变量.请注意,参数名称是一个基于 0 的计数器,对应于 ?.例如,请参见屏幕显示.在我的测试中,我使用了 PackageName 和 StartTime 的系统变量.

On the Parameter Mapping Screen add your two variables. Note that the Parameter Name is a 0 based counter that corresponds to the ?. See screen show for example. In my test I used the system variables for PackageName and StartTime.

注意:我选择删除并替换示例中的表格.您很可能希望拥有此静态数据,并且可能会向表中添加一个日期时间以随着时间的推移跟踪变量.

Note: I opted to drop and replace the table for the example. Most likely you will want to have this static and maybe add a datetime to the table to track the vars over time.

注意 2:我知道开始时间不是 varchar,但它符合示例的目的.

Note2: I know start time isn't a varchar but it serves the purpose of the example.

更多推荐

如何使用 SSIS 包中的变量值加载新表?

本文发布于:2023-10-27 16:19:21,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1533903.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何使用   包中   加载   变量值   SSIS

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!