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

Mat*_*att 1 qlikview qliksense

我有一个具有值的字段

field
good - examplea
good - exampleb
bad - examplep
ugly - examplet
ugly - exampley
Run Code Online (Sandbox Code Playgroud)

我想只在-角色后面显示值.

我的示例输出将是

field
examplea
exampleb
examplep
examplet
exampley
Run Code Online (Sandbox Code Playgroud)

在SQL中它会很简单

SUBSTRING('ugly - exampley',CHARINDEX('- ', 'ugly - exampley', 1)+2,250)
Run Code Online (Sandbox Code Playgroud)

SUBSTRING(field,CHARINDEX('- ', field, 1)+2,250)
Run Code Online (Sandbox Code Playgroud)

Qlikview中的equivelant是什么?

i_s*_*nes 5

您可以使用mid(with index)或subfield如下:

中期和指数

你的陈述相当于:

mid(field, index(field,'- ', 1) + 2, 250) 
Run Code Online (Sandbox Code Playgroud)

在这里,mid相当于SUBSTRINGindex等价物CHARINDEX.但是,在QlikView中,mid第三个参数(要返回的字符数)是可选的,因此您可以改为使用

mid(field, index(field,'- ', 1) + 2) 
Run Code Online (Sandbox Code Playgroud)

这将返回字段值后的剩余部分-.

子场

Subfield允许您使用另一个字符串分隔输入字符串,然后返回特定的分隔子字符串.在你的情况下,下面将做的伎俩:

subfield(field, ' - ' , 2)
Run Code Online (Sandbox Code Playgroud)

例如,对于字符串good - examplea,这会通过查找分隔符将其分解-.这导致两个字符串,goodexamplea.最后一个参数2告诉subfield返回examplea(而不是good通过使用1第三个参数获得).

在您的情况下,子字段的好处是您不需要指定要返回的字符数,因为子字段会将所有字符返回到字符串的末尾.