我正在使用SSIS,我有一个脚本任务,如果今天的日期是月初,我想更改变量的值。
所以我想将布尔变量startDate
的值更改为TRUE,如果它是任务运行的月份的开头,否则为FALSE。
基本上我错过了这个SQL语句的SSIS Script版本:
SELECT DATEADD(month, DATEDIFF(month, 0, @mydate), 0) AS StartOfMonth
到目前为止,这是我的脚本:
public void Main()
{
if (DateTime.Today = ? )
{
Dts.Variables["User::startDate"].Value = True;
}
Dts.Variables["User::startDate"].Value = False;
Dts.TaskResult = (int)ScriptResults.Success;
}
}
解答:
public void Main()
{
DateTime value = new DateTime(DateTime.Today.Year,DateTime.Today.Month,1);
if (DateTime.Today == value )
{
Dts.Variables["User::startDate"].Value = bool.Parse("True");
}
Dts.Variables["User::startDate"].Value = bool.Parse("False");
Dts.TaskResult = (int)ScriptResults.Success;
}
}
答案 0 :(得分:1)
只需使用:
public void Main()
{
DateTime value = new DateTime(DateTime.Today.Year,DateTime.Today.Month,1);
if (DateTime.Today == value )
{
Dts.Variables["User::startDate"].Value = bool.Parse("True");
}
Dts.Variables["User::startDate"].Value = bool.Parse("False");
Dts.TaskResult = (int)ScriptResults.Success;
}
}