Axapta 中 Where 子句中的变量

Variable in Where Clause in Axapta

我在 axapta 的作业中有一个更新语句,我想在更新 where 子句中使用一个变量

static void UpdateSomeValues(Args _args)
{
    Table myTable;
    str likeThis;
    ;

    likeThis = 'W200';

    ttsBegin;
    select forUpdate myTable
    where myTable.start == 'W100'
    && myTable.destination like likeThis;

    myTable.AlloweMove = NoYes::Yes;
    myTable.AllowStop = NoYes::Yes;

    ttsCommit;
}

我得到的错误是这样翻译的:

where 子句中不允许使用未绑定的字符串

是否有在 x++ 的 where 子句中使用字符串的解决方法?

出现错误,因为字符串的长度是无限的。尝试使用适当的 EDT 或类似 str 50 likeThis;

static void UpdateSomeValues(Args _args)
{
    Table myTable;
    str 50 likeThis;
    ;

    likeThis = 'W200';

    ttsBegin;
    select forUpdate myTable
    where myTable.start == 'W100'
    && myTable.destination like likeThis;

    myTable.AlloweMove = NoYes::Yes;
    myTable.AllowStop = NoYes::Yes;

    ttsCommit;
}

Is there a workaround to use Strings in the where clause in x++ ?

是的,您必须使用有界字符串,这是定义了最大长度的字符串。这就是为什么通常使用扩展数据类型作为变量的数据类型的原因,因为扩展数据类型的属性已经定义了最大长度。但是如果你不能使用扩展数据类型,你也可以像这样设置一个字符串变量的最大长度:

str 4 likeThis;
;

likeThis = 'W200';

str后面的数字定义了变量的最大长度。然后可以在 select 语句的 where 子句中使用此变量。

也看看Strings [AX 2012]