简体   繁体   English

SSIS:比较日期时间与变量

[英]SSIS: Comparing datetime with a variable

So, I have created a variable "batch" with datatype datetime. 因此,我创建了一个数据类型为datetime的变量“批处理”。 Now my OLEBD source has a column "addDate" eg 2012-05-18 11:11:17.470 so does empty destination which is to be populated. 现在,我的OLEBD源具有一列“ addDate”,例如2012-05-18 11:11:17.470,因此要填充的空目标也是如此。

now this column addDate has many dates and I want to copy all dates which are "2012-05-18 11:11:17.470" 现在,此列addDate具有许多日期,我想复制所有日期为“ 2012-05-18 11:11:17.470”的日期

When I put value of the variable as this date, it automatically changes to mm/dd/yyyy hh;mm AM format and hence in my conditional split transformation, it couldn't match the date with the variable and hence no records are getting copied to the destination !! 当我将变量的值作为该日期时,它会自动更改为mm / dd / yyyy hh; mm AM格式,因此在我的条件拆分转换中,它无法将日期与变量匹配,因此不会复制任何记录到目的地!

Where exactly is the problem? 问题到底在哪里?

Thanks! 谢谢!

I had this issue and the best solution I found is not “pretty”. 我遇到了这个问题,发现的最佳解决方案不是“漂亮”。 Basically you need to change the “expression” of the variable and the “evaluate as expression” to true (otherwise it will ignore the value on expression). 基本上,您需要将变量的“表达式”和“作为表达式求值”更改为true(否则它将忽略表达式上的值)。

The secret is (and kind of the reason I said it is not a pretty solution) to create a second variable to evaluate the expression of the first variable because you can't change the value of a variable based on a expression. 秘诀是(并且我说这不是一个很好的解决方案的原因)是创建第二个变量来评估第一个变量的表达式,因为您不能基于表达式来更改变量的值。

So let's say your variable is called “DateVariable” and you have 23/05/2012 , create a variable called “DateVar2” for example and set its expression to 假设您的变量名为“ DateVariable”,而您有23/05/2012 ,例如,创建一个名为“ DateVar2”的变量并将其表达式设置为

(DT_WSTR,4)YEAR(@[User::DateVariable]) + "/"+RIGHT("0" + (DT_WSTR,2)MONTH(@[User::DateVariable]),2) + "/" + RIGHT("0" + (DT_WSTR,2)DAY(@[User::DateVariable]),2) (DT_WSTR,4)YEAR(@ [User :: DateVariable])+“ /” + RIGHT(“ 0” +(DT_WSTR,2)MONTH(@ [User :: DateVariable]),2)+“ /” + RIGHT (“ 0” +(DT_WSTR,2)DAY(@ [User :: DateVariable]),2)

That will give you 2012/05/23 那会给你2012/05/23

Just keep going to get the date on the format you want 只需继续获取所需格式的日期即可

I found the easier solution. 我找到了更简单的解决方案。 Select datatype as string. 选择数据类型作为字符串。 put any desired value. 放置任何期望的值。 Before conditional split, you need data conversion transformation. 在条件拆分之前,需要进行数据转换转换。 convert it into DT_DBTIMESTAMP then run the package. 将其转换为DT_DBTIMESTAMP,然后运行该程序包。

It works! 有用!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM