首页 > 解决方案 > 使用表达式生成器评估表达式

问题描述

我是 ssis 的新手,我想使用表达式生成器对此进行评估,以获取 bigin 中的当前日期。任何想法?

DATEPART(second, getdate()) +
        DATEPART(minute, getdate()) * 100 +
        DATEPART(hour, getdate()) * 10000 +
        DATEPART(day, getdate()) * 1000000 +
        DATEPART(month, getdate()) * 100000000 +
        DATEPART(year, getdate()) * 10000000000

错误是

无法评估表达式。

------------------------------
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)

------------------------------

标签: ssis

解决方案


DATEPARTSSIS 表达式中的语法与 TSQL 中的语法不同。因为这有助于使我们的生活变得比必要的更加艰难。

第一个参数 ,datepart必须用双引号括起来。这应该让你更接近你所追求的。

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您可以通过在最后一个文字的末尾添加一个来修复该问题:

DATEPART("second", getdate()) +
DATEPART("minute", getdate()) * 100 +
DATEPART("hour", getdate()) * 10000 +
DATEPART("day", getdate()) * 1000000 +
DATEPART("month", getdate()) * 100000000 +
DATEPART("year", getdate()) * 10000000000L

并且正确评估为20200611143622.


推荐阅读