Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CASE in a Where clause? 1

Status
Not open for further replies.

ecobb

Programmer
Dec 5, 2002
2,190
US
Is is possible to use CASE in a Where clause? I'm trying to find an easier way to do the following. This is in a Stored Procedure I'm writing, rather than having 15 Select statements, is there some way I can have a dynamic where clause and just use 1 statement?
Code:
IF @Type = 'Sales'
  BEGIN
    Select IncidentID, IncidentDate, Customer, JobName, JobNumber
    From dbo.Incidents
    Where Sales = 1
    Order By IncidentID
  END

IF @Type = 'Quality'
  BEGIN
    Select IncidentID, IncidentDate, Customer, JobName, JobNumber
    From dbo.Incidents
    Where Quality = 1
    Order By IncidentID
  END

IF @Type = 'Production'
  BEGIN
    Select IncidentID, IncidentDate, Customer, JobName, JobNumber
    From dbo.Incidents
    Where Production = 1
    Order By IncidentID
  END

.....Several More of the same type SQL statements...

Hope This Helps!

ECAR
ECAR Technologies

"My work is a game, a very serious game." - M.C. Escher
 
Use 'OR'

Where (Sales = 1 and @Type = 'Sales')
OR (Quality = 1 and @Type = 'Quality')

...


- Paul
10qkyfp.gif

- If at first you don't succeed, find out if the loser gets anything.
 
I hate it when I miss something so obvious! [banghead]

Thanks, Paul!!!


Hope This Helps!

ECAR
ECAR Technologies

"My work is a game, a very serious game." - M.C. Escher
 
[lol]
Don't worry about it. I did the same thing a week or so ago. I only knew the answer thank to Alex.
[small] props to AlexCuse[/small]

thread183-1358262

- Paul
10qkyfp.gif

- If at first you don't succeed, find out if the loser gets anything.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top