虽然值可能存储在 internal.object_parameters 中,但请抵制直接编辑这些表中的值的诱惑。而是使用提供的方法进行操作。在这种情况下,存储过程catalog.set_environment_variable_value。
下面是如何以编程方式更改环境变量值的示例。我会将此视为 SQL 代理作业中的 TSQL 作业步骤,该作业在您的包启动之前运行,以确保按预期设置 StartDateTime 和 EndDateTime 的正确值。
DECLARE @var sql_variant;
DECLARE
@StartDateTime date
, @EndDateTime datetime
, @RunType bit = 1;
SELECT
@StartDateTime = CAST(dateadd(d, -1, CURRENT_TIMESTAMP) AS date)
, @EndDateTime = DATEADD(s, -1, cast(cast(current_timestamp AS date) AS datetime))
SELECT @StartDateTime, @EndDateTime;
IF (@RunType = 1)
BEGIN
SET @var = @StartDateTime;
EXECUTE [SSISDB].[catalog].[set_environment_variable_value]
@variable_name=N'StartDateTime'
, @environment_name=N'MyEnvironmentName'
, @folder_name=N'MyFolder'
, @value=@var;
SET @var = @EndDateTime;
EXECUTE [SSISDB].[catalog].[set_environment_variable_value]
@variable_name=N'EndDateTime'
, @environment_name=N'MyEnvironmentName'
, @folder_name=N'MyFolder'
, @value=@var;
END
ELSE
BEGIN
PRINT 'Logic goes here to handle the other conditions for RunType'
END