Qlikview Substring 和 charindex 相当于在 - 字符后显示值

Qlikview Substring and charindex equivalent to show values after the - character

我有一个具有值的字段

field
good - examplea
good - exampleb
bad - examplep
ugly - examplet
ugly - exampley

我只想显示 - 字符后的值。

我的示例输出是

field
examplea
exampleb
examplep
examplet
exampley

在 SQL 中就是

SUBSTRING('ugly - exampley',CHARINDEX('- ', 'ugly - exampley', 1)+2,250)

SUBSTRING(field,CHARINDEX('- ', field, 1)+2,250)

Qlikview 中的等价物是什么

您可以使用 mid(带 index)或 subfield,如下所示:

中间和指数

你的陈述等价于:

mid(field, index(field,'- ', 1) + 2, 250) 

这里,mid相当于SUBSTRINGindex相当于CHARINDEX。但是,在 QlikView 中,mid 的第三个参数(return 的字符数)是可选的,因此您可以改为使用

mid(field, index(field,'- ', 1) + 2) 

return -.

之后字段值的剩余部分

子字段

Subfield 允许您用另一个字符串分隔输入字符串,然后 return 一个特定的分隔子字符串。在您的情况下,以下内容可以解决问题:

subfield(field, ' - ' , 2)

例如,对于字符串 good - examplea,这将通过查找分隔符 - 将其分解。这会产生两个字符串,goodexamplea。最后一个参数 2 告诉 subfield 到 return examplea (而不是 good 可以通过使用 1 作为第三个参数来获得).

在您的情况下,关于子字段的好处是您不需要指定 return 的字符数,因为子字段将 return 所有字符到字符串的末尾。