select
SUBSTRING(ackey,1,2) + '-' + SUBSTRING(ackey, 3,3) + '-' + SUBSTRING(ackey,8,6)
from
tHE_Move
where case
when acDocType in ('1900', '1910', '1920', '1930') then acWayOfSale <> 'E'
when acDocType in ('1950', '1960') then acWayOfSale <> 'U'
我可以這樣做嗎?如何在WHERE子句中使用CASE
我解決了這個有:
select
SUBSTRING(ackey,1,2) + '-' + SUBSTRING(ackey, 3,3) + '-' + SUBSTRING(ackey,8,6)
from
tHE_Move
where
(case when acDocType in ('1900', '1910', '1920', '1930') then acWayOfSale end <> 'E'
or
case when acDocType in ('1950','1960') then acWayOfSale end <> 'U')
但我有興趣,如果這隻能在一個情況下得到解決?
你並不是真的需要'case' - 只需要用'AND'和'OR'將邏輯片段結合在一起。 'CASE'是爲了返回*值*的*表達式。 – 2014-10-31 13:46:10