将一天添加到DateTime项目参数中,并将存储在使用SSIS表达式的类型DateTime变量中

发布于 2025-02-03 08:25:19 字数 1238 浏览 3 评论 0原文

我正在尝试将一天添加到类型DateTime的项目参数中,并将结果存储在SSIS中的变量中。

我在可变中使用以下表达式

dateadd(day,1,(DT_DATE)(DT_DBDATE) @[$Project::Start_Date])

并获取以下错误

标题:表达式建筑商

无法评估表达。

寻求帮助,单击: http://go.microsoft.com/forosoft.com/fwwlink?prodname = microsoftemoffiofiof; = 14.0.23107.0& evtsrc = microsoft.datatRansformationservices.controls.taskuiframework.taskuiframeworksr&evtid = failToToToVato = failToevaluydExpression& linkID& linkID = 20476

------------------------------ ADDITIONAL INFORMATION:

该表达式包含未识别的令牌“ Day”。如果“一天”是 变量,应表示为“@day”。指定的令牌不是 有效的。如果令牌旨在是可变名称,则应该是 前缀为 @符号。

尝试解析表达式“ dateadd(Day,1,(dt_date)(dt_dbdate)) @[$ project :: start_date])“失败并返回错误代码0xc00470a4。 表达不能解析。它可能包含无效元素或 它可能不是很好的。也可能存在误解。

(Microsoft.datatransformationservices.controls)

-------------------------------------------按钮:

OK

帮助我解决上述问题。

I am trying to add a day to a project parameter of type DATETIME and store the results in a variable in SSIS which of type DATETIME.

I am using this below expression in variable

dateadd(day,1,(DT_DATE)(DT_DBDATE) @[$Project::Start_Date])

and getting this below error

TITLE: Expression Builder

Expression cannot be evaluated.

For help, click:
http://go.microsoft.com/fwlink?ProdName=Microsoft%C2%AE%20Visual%20Studio%C2%AE%202015&ProdVer=14.0.23107.0&EvtSrc=Microsoft.DataTransformationServices.Controls.TaskUIFramework.TaskUIFrameworkSR&EvtID=FailToEvaluateExpression&LinkId=20476

------------------------------ ADDITIONAL INFORMATION:

The expression contains unrecognized token "day". If "day" is a
variable, it should be expressed as "@day". The specified token is not
valid. If the token is intended to be a variable name, it should be
prefixed with the @ symbol.

Attempt to parse the expression "dateadd(day,1,(DT_DATE)(DT_DBDATE)
@[$Project::Start_Date])" failed and returned error code 0xC00470A4.
The expression cannot be parsed. It might contain invalid elements or
it might not be well-formed. There may also be an out-of-memory error.

(Microsoft.DataTransformationServices.Controls)

------------------------------ BUTTONS:

OK

Can anyone help me to resolve the above problem.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你怎么这么可爱啊 2025-02-10 08:25:19

tl; dr;

DATEADD的第一个参数的参数是字符串,而不是常数/枚举,因此应该是

dateadd("day",1,(DT_DATE)(DT_DBDATE) @[$Project::Start_Date])

很长的路,

获得第二天的日期

dateadd(day,1,(DT_DATE)(DT_DBDATE) @[$Project::Start_Date])

我认为愿望是在我遇到表达式问题时 ,我会破裂它们进入最原子的陈述,然后从那里构成。

我使用的是SSIS范围的变量,而不是项目参数,但逻辑将保持真实。

我有一个SSIS变量,数据类型DateTime的启动_DATE,其初始值2022-06-01 09:22 AM(将其转换为您当前的网站对日期的偏爱)

我创建了一个新的变量, start_dateonly并使用以下表达式

(DT_DATE)(DT_DBDATE)  @[User::Start_Date]

出色,该表达式显示为2022-06-01(尽管您在Expresse Editor中进行了评估,但它将显示午夜)。和解释器 - 我们将其转换为DT_DBDATE数据类型以删除时间组件,但DT_DBDATE与显示的DateTime数据类型不兼容,因此我们明确转换为DT_DATE。

酷豆,现在我们要做的就是确认数据函数按预期使用我们的新变量可行,

dateadd(day, 1, @[User::Start_DateOnly])

什么是什么?

无法评估表达。

该表达式包含未识别的令牌“ Day”。如果“天”是一个变量,则应表示为“@day”。指定的令牌无效。如果令牌旨在成为变量名,则应将其前缀为 @符号。

哦...是的,虽然这种语言类似于tsql,但datePart参数是字符串,而不是枚举/常数,因此语法应该是

dateadd("day", 1, @[User::Start_DateOnly])

yup,它评估为2022-06-06-02 12:00 AM

TL;DR;

The argument to the first parameter for dateadd is a string, not a constant/enumeration so it should be

dateadd("day",1,(DT_DATE)(DT_DBDATE) @[$Project::Start_Date])

The long way around

I assume the desire is to get the next day's date with the supplied expression

dateadd(day,1,(DT_DATE)(DT_DBDATE) @[$Project::Start_Date])

When I run into issues with expressions, I break them down into the most atomic statement and then compose from there.

I'm using a SSIS scoped variable instead of a project parameter but the logic will hold true.

I have an SSIS variable, Start_Date of data type DateTime with an initial value of 2022-06-01 09:22 AM (convert that to your current locale's preference for date presenation)

I created a new variable, Start_DateOnly and used the following expression

(DT_DATE)(DT_DBDATE)  @[User::Start_Date]

Great, that shows 2022-06-01 (no time component in the Variables window although if you evaluate in the Expression editor, it will show midnight). And the explainer - we convert to the DT_DBDATE datatype to drop the time component but DT_DBDATE is incompatible with the displayed DateTime data type so we explicitly convert to DT_DATE.

Cool beans, now all we need to do is confirm the dateadd function works as expected with our new variable

dateadd(day, 1, @[User::Start_DateOnly])

What the heck?

Expression cannot be evaluated.

The expression contains unrecognized token "day". If "day" is a variable, it should be expressed as "@day". The specified token is not valid. If the token is intended to be a variable name, it should be prefixed with the @ symbol.

Oh... yeah, while this language is similar to TSQL, the datepart parameter is a string, not an enum/constant so the syntax should be

dateadd("day", 1, @[User::Start_DateOnly])

Yup, that evaluates to 2022-06-02 12:00 AM

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文