首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用表达式构建器计算表达式

使用表达式构建器计算表达式
EN

Stack Overflow用户
提问于 2020-06-11 22:56:19
回答 1查看 79关注 0票数 1

我是ssis的新手,我想使用表达式生成器来评估它,以获得bigin中的当前日期。有什么想法吗?

代码语言:javascript
复制
DATEPART(second, getdate()) +
        DATEPART(minute, getdate()) * 100 +
        DATEPART(hour, getdate()) * 10000 +
        DATEPART(day, getdate()) * 1000000 +
        DATEPART(month, getdate()) * 100000000 +
        DATEPART(year, getdate()) * 10000000000

错误是

无法计算表达式。

代码语言:javascript
复制
------------------------------
ADDITIONAL INFORMATION:

The expression contains unrecognized token "second". If "second" is a variable, it should be expressed as "@second". 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 "DATEPART(second, getdate()) +
        DATEPART(minute, getdate()) * 100 +
        DATEPART(hour, getdate()) * 10000 +
        DATEPART(day, getdate()) * 1000000 +
        DATEPART(month, getdate()) * 100000000 +
        DATEPART(year, getdate()) * 10000000000" 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)

------------------------------
EN

回答 1

Stack Overflow用户

发布于 2020-06-12 03:37:24

SSIS表达式中的DATEPART语法与TSQL中的语法不同。因为这会让我们的生活变得更加艰难。

第一个参数datepart必须用双引号括起来。这应该会让你更接近你想要的。

代码语言:javascript
复制
DATEPART("second", getdate()) +
DATEPART("minute", getdate()) * 100 +
DATEPART("hour", getdate()) * 10000 +
DATEPART("day", getdate()) * 1000000 +
DATEPART("month", getdate()) * 100000000 +
DATEPART("year", getdate()) * 10000000000

您将得到的下一个错误是:

文字"10000000000“太大,无法放入类型DT_I4中。文字的大小会使类型溢出。

您可以通过在最后一个文字的末尾添加一个L来解决这个问题:

代码语言:javascript
复制
DATEPART("second", getdate()) +
DATEPART("minute", getdate()) * 100 +
DATEPART("hour", getdate()) * 10000 +
DATEPART("day", getdate()) * 1000000 +
DATEPART("month", getdate()) * 100000000 +
DATEPART("year", getdate()) * 10000000000L

并正确评估为20200611143622

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62327258

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档