Sql 在where子句中将case语句转换为逻辑运算符
你能帮我把这段代码转换成逻辑运算符并使用Sql 在where子句中将case语句转换为逻辑运算符,sql,Sql,你能帮我把这段代码转换成逻辑运算符并使用'like'而不是'='吗?因为我知道把case语句放在where子句上是没有效率的。蒂亚!这是密码 Where (@reftype = '0' or (@refnum = case @reftype when 'BN' then refBN when 'C' then refC when 'O' then refO else 'n/a' end) ) 替换 or @refnum = case @reftype when 'BN' then refB
'like'
而不是'='
吗?因为我知道把case语句放在where子句上是没有效率的。蒂亚!这是密码
Where
(@reftype = '0' or
(@refnum = case @reftype when 'BN' then refBN when 'C' then refC when 'O' then refO else 'n/a' end)
)
替换
or @refnum = case @reftype when 'BN' then refBN when 'C' then refC when 'O' then refO else 'n/a' end)
与
您可以通过以下方式将其转换为布尔逻辑:
WHERE @reftype = '0 'OR @refnum = 'n/a'
OR (@reftype = 'BN' AND @refnum = refbn)
OR (@reftype = 'C' AND @refnum = refc)
OR (@reftype = 'O' AND @refnum = refo)
但是请注意,
WHERE
-子句中的CASE
本身并不低效。感谢您编辑Tim。我确实翻译了,但我的上司说它错了。这是我的代码:其中(@reftype='0'或(@reftype='BN'和refBN像@refnum)或(@reftype='C'和refC像@refnum)或(@reftype='O'和refO像@refnum)或(@reftype='n/a')我不知道我遗漏了什么。谢谢蒂姆。看起来也是我翻译的。我不知道为什么我的上司对此不高兴。
WHERE @reftype = '0 'OR @refnum = 'n/a'
OR (@reftype = 'BN' AND @refnum = refbn)
OR (@reftype = 'C' AND @refnum = refc)
OR (@reftype = 'O' AND @refnum = refo)