2015-08-27 86 views
0

您可以幫助我將這段代碼轉換爲邏輯運算符,並使用'like'而不是'='因爲我知道將where語句放在where子句上效率不高。蒂亞!這是代碼。將case 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) 
) 
+0

感謝您編輯Tim。我做了翻譯,但我的上司說錯了。這裏是我的代碼:其中(@ reftype ='0'或(@reftype ='BN'和refBN如@refnum)或(@ reftype ='C'和refC像@refnum)或(@ reftype ='O'和refO就像@ refnum)或(@ reftype ='n/a'))我不知道我在想什麼。 – jian

回答

0

更換

or @refnum = case @reftype when 'BN' then refBN when 'C' then refC when 'O' then refO else 'n/a' end) 

or (@reftype = 'BN' AND @refnum = refBN) 
or (@reftype = 'C' AND @refnum = refC) 
or (@reftype = 'O' AND @refnum = refO) 
or @refnum = 'n/a' 
+0

謝謝juergen。 – jian

0

您可以用這種方法把它轉變爲布爾邏輯:

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) 

但請注意,CASEWHERE條本身並不是無效的。

+0

謝謝蒂姆。看起來像我翻譯的那個。我不知道我的上司爲什麼不開心。 – jian

+0

@jian:然後問他 –

+0

謝謝你回答我的問題。 – jian