6

大家好(我在堆栈上的第一篇文章!),

这有效:

where
    Tran_date between @FromDate and @ToDate

and Range = @Range

and Store_ID =
    case when @Range = 'RangeName' then
        1234
    else
        Store_ID
    end

但我怎样才能做到这一点?:

where
    Tran_date between @FromDate and @ToDate

and Range = @Range

and Store_ID 
    case when @Range = 'RangeName' then
        not in (1234, 5678)
    else
        Store_ID
    end
4

3 回答 3

5
where
    Tran_date between @FromDate and @ToDate

and Range = @Range

and Store_ID 
    case when @Range = 'RangeName' AND Store_Id in (1234, 5678)
        9999 -- Assumes 9999 is a non possible value.  
             -- If it is possible then pick one that isn't.
    else
        Store_ID
    end
于 2013-02-13T00:53:09.247 回答
2

我想你想要:

AND NOT (@Range = 'RangeName' AND Store_ID IN (1234,5678))
于 2013-02-12T23:54:20.070 回答
0

这个怎么样:

where Tran_date between @FromDate and @ToDate
    and Range = @Range

    and (@Range = 'RangeName' and Store_ID not in (1234, 5678)
        or @Range <> 'RangeName' and Store_ID = Store_ID)
于 2013-02-12T23:53:58.353 回答