SSIS 用户变量分配 [英] SSIS User Variable Assignment

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

问题描述

有谁知道如何在 SSIS 脚本中将一个用户变量分配给另一个用户变量?

Does anyone know how to assign one user variable to another in script in SSIS?

我有两个用户变量,都是 DateTime 类型.

I have two user variables, both of them are DateTime type.

我尝试在脚本任务中将一个分配给另一个,但出现无效类型错误

I try to assign one to the other in a script task and I get an invalid type error

Dts.Variables["Query_AccountingDay"].Value = Dts.Variables["Override_AccountingDay"].Value;

给我错误:错误:System.Reflection.TargetInvocationException:调用的目标已抛出异常.---> Microsoft.SqlServer.Dts.Runtime.DtsRuntimeException:分配给变量User::Query_AccountingDay"的值类型与当前变量类型不同.变量在执行期间可能不会改变类型.变量类型是严格的,Object 类型的变量除外.

Gives me the error: Error: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> Microsoft.SqlServer.Dts.Runtime.DtsRuntimeException: The type of the value being assigned to variable "User::Query_AccountingDay" differs from the current variable type. Variables may not change type during execution. Variable types are strict, except for variables of type Object.

我试过铸造,那不起作用.

Iv tried casting, that doesnt work.

请帮忙

推荐答案

所以你试过了?

Dts.Variables["Query_AccountingDay"].Value = Convert.ToDateTime(Dts.Variables["Override_AccountingDay"].Value.ToString());

如果这不起作用,介意抓取一个变量窗口的快速屏幕截图,以便我们可以验证数据类型吗?

If that isn't working, mind grabbing a quick screenshot of the variables window so that we can verify data types?

我的看起来像这样,覆盖值是 2007-07-07,查询是 2011-10-19

Mine looks like this, Override value is 2007-07-07, Query is 2011-10-19

脚本任务如此配置

代码体看起来像这样

    public void Main()
    {
        MessageBox.Show(String.Format("{0}:{1}", "Override_AccountingDay", Dts.Variables["Override_AccountingDay"].Value));
        MessageBox.Show(String.Format("Before {0}:{1}", "Query_AccountingDay", Dts.Variables["Query_AccountingDay"].Value));

        Dts.Variables["Query_AccountingDay"].Value = Convert.ToDateTime(Dts.Variables["Override_AccountingDay"].Value.ToString());
        Dts.TaskResult = (int)ScriptResults.Success;

        MessageBox.Show(String.Format("After {0}:{1}", "Query_AccountingDay", Dts.Variables["Query_AccountingDay"].Value));
    }

通过消息框的执行结果

---------------------------

---------------------------
Override_AccountingDay:7/7/2007 7:37:36 AM
---------------------------
OK   
---------------------------

---------------------------

---------------------------
Before Query_AccountingDay:10/19/2011 7:37:41 AM
---------------------------
OK   
---------------------------

---------------------------

---------------------------
After Query_AccountingDay:7/7/2007 7:37:36 AM
---------------------------
OK   
---------------------------

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

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