[英]How can I use `IN` with a list of strings?
I am trying to replace semicolon-separated strings(;) with comma-separated strings(,) in the where condition and have tried this in the where clause but I do not work.我试图在 where 条件中用逗号分隔的字符串(,)替换分号分隔的字符串(;),并在 where 子句中尝试过,但我不工作。 Can anyone help me with the solution?
谁能帮我解决问题?
s.securitydepartment in (REPLACE('Leverkusen;Waterford',';',','))
As mentioned in the comments, what you probably want is something like this:正如评论中提到的,你可能想要的是这样的:
SELECT {Your Columns}
FROM {Your Table} YT
JOIN STRING_SPLIT('Leverkusen;Waterford',';') SS ON YT.securitydepartment = SS.[Value]
WHERE ...
Of course, however, as 'Leverkusen;Waterford'
is a literal though, why not just fix the query and do:但是,当然,由于
'Leverkusen;Waterford'
是字面意思,为什么不直接修复查询并执行以下操作:
s.securitydepartment IN ('Leverkusen','Waterford')
In
is a operator that works on a set , not a string. In
是一个适用于集合的运算符,而不是字符串。
You need to provide a set of values, a string is not "parsed" in any way or treated as a comma-separated list.您需要提供一组值,字符串不会以任何方式“解析”或视为逗号分隔的列表。
You can use string_split
to return a set of values, for example您可以使用
string_split
返回一组值,例如
and s.securityDepartment in (select value from string_split('value1;value2;value3',';'))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.