# how use SQL WHERE CASE with NOT IN or equals at the same time?

Hi all (my first post on the Stack!),

This works:

``````where
Tran_date between @FromDate and @ToDate

and Range = @Range

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

but how can I achieve this?:

``````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
``````

I think you want:

``````AND NOT (@Range = 'RangeName' AND Store_ID IN (1234,5678))
``````
``````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
``````

``````where Tran_date between @FromDate and @ToDate
{"ft_lang_label":"__label__en","ft_lang_prob":0.66394407,"math_prob":0.86446196,"size":369,"snap":"2019-43-2019-47","text_gpt3_token_len":114,"char_repetition_ratio":0.16164383,"word_repetition_ratio":0.33333334,"special_character_ratio":0.29268292,"punctuation_ratio":0.092307694,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.98347867,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2019-11-13T09:36:58Z\",\"WARC-Record-ID\":\"<urn:uuid:f97fbb27-7ded-40a5-adb3-8f279259395f>\",\"Content-Length\":\"149076\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:dde13af2-e5de-41cf-8ef4-1e8ec1ba9aaa>\",\"WARC-Concurrent-To\":\"<urn:uuid:a597ad1e-d35c-443b-a734-cb20743ae176>\",\"WARC-IP-Address\":\"151.101.129.69\",\"WARC-Target-URI\":\"https://stackoverflow.com/questions/14844006/how-use-sql-where-case-with-not-in-or-equals-at-the-same-time\",\"WARC-Payload-Digest\":\"sha1:HJB7JMVNU3EBC4XUNLILBDP7J4HHB7FT\",\"WARC-Block-Digest\":\"sha1:WTFFQMUKHQRI3RRCG2THUX2AJ4NCIY7N\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2019/CC-MAIN-2019-47/CC-MAIN-2019-47_segments_1573496667177.24_warc_CC-MAIN-20191113090217-20191113114217-00404.warc.gz\"}"}