[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 351
  • Last Modified:

SQL WHERE CASE question

I need to perform a search based on the following concept

Select A
Where case when G=1 then X in (b,c,d) else X like 'Y' end

No matter what I try, I can't get it to work.

Suggestions?  I know it looks screwy.
0
simplyfemales
Asked:
simplyfemales
2 Solutions
 
Aaron ShiloCommented:
select A
From table
Where case when G=1 then X in (b,c,d) else X like 'Y' end

0
 
simplyfemalesAuthor Commented:
Ashilo,

My mistake, yes the "from table" is there, the where clause is the portion that's not working.
0
 
Aaron ShiloCommented:
ok

it looks like youl need to use a Storedprocedure and build your query dynamicly.
0
 
Ephraim WangoyaCommented:


Select A
Where (( G=1) and (X in (b,c,d)))
or ((G <> 1) and (X like 'Y'))
0
 
SharathData EngineerCommented:
try this.
SELECT A 
 WHERE (G = 1 
        AND X IN ('b','c','d')) 
        OR (G <> 1 
            AND X = 'Y')

Open in new window

0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now