Solved

sql server using case statement in where clause

Posted on 2016-08-08
3
38 Views
Last Modified: 2016-08-08
currently I have a where clause that looks like this:
where rs.status in ('Open', 'Confirmed', 'Arrived')

this is what I'm trying:
where case
     when @hp=1 then in ('Open', 'Confirmed', 'Arrived')
     else in ('Open', 'Confirmed', 'Arrived', 'High Probability')
     end

what am I doing wrong?
0
Comment
Question by:dhenderson12
  • 2
3 Comments
 

Author Comment

by:dhenderson12
Comment Utility
sorry, mis-typed.
this is what I'm trying:
where case
     when @hp=1 then rs.status in ('Open', 'Confirmed', 'Arrived')
     else rs.status in ('Open', 'Confirmed', 'Arrived', 'High Probability')
     end
0
 
LVL 65

Accepted Solution

by:
Jim Horn earned 500 total points
Comment Utility
Give this a whirl..
WHERE
   ( @hp = 1 AND rs.status in ('Open', 'Confirmed', 'Arrived')) OR 
   ( @hp <> 1 AND rs.status in ('Open', 'Confirmed', 'Arrived', 'High Probability'))

Open in new window

0
 

Author Comment

by:dhenderson12
Comment Utility
sorry, that didn't work ... got the same records.  ended up doing an "IF / ELSE" statement .
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

After restoring a Microsoft SQL Server database (.bak) from backup or attaching .mdf file, you may run into "Error '15023' User or role already exists in the current database" when you use the "User Mapping" SQL Management Studio functionality to al…
How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now