将 SQL 转换为 X++

Converting SQL to X++

我想将以下 SQL 转换为 X++

case when CHARINDEX('-',REVERSE(NAME)) > 0 then right(NAME,CHARINDEX('-',REVERSE(NAME))-1) else Name end as Name

下面是 SQL 函数的 X++ 等价物:

CHARINDEX     strScan
REVERSE       strReverse
RIGHT         subStr

X++ string runtime functions

str result;

result = strScan(name, '-', strLen(name), -strLen(name)) > 0 ?
            strDel(name, 1, strScan(name, '-', strLen(name), -strLen(name))) :
            name;

// Just an observation, the following would actually give the same result

result = strDel(name, 1, strScan(name, '-', strLen(name), -strLen(name)));

请注意,此类字符串函数不能用于 SELECT 语句、WHERE 子句等。如果这是绝对必要的,解决方法是 use computed columns in views.