1
我正在使用SSIS,并且我有一个脚本任务,如果今天的日期是月初,我想更改变量的值。如何在SSIS脚本任务中获取月初的日期?
所以我想改变布尔变量startDate
的值为TRUE,如果它是任务运行的月份的开始,否则返回FALSE。
基本上我缺少这个SQL语句的SSIS脚本版本:
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 – Hadi
请记住,变量名称区分大小写 – Hadi