使用表达式构建器评估表达式

问题描述 投票:0回答:1

我是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
1个回答
0
投票

SSIS表达式中DATEPART的语法与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

© www.soinside.com 2019 - 2024. All rights reserved.