Solved

sql server using case statement in where clause

Posted on 2016-08-08
3
54 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
ID: 41747505
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
ID: 41747518
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
ID: 41747592
sorry, that didn't work ... got the same records.  ended up doing an "IF / ELSE" statement .
0

Featured Post

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

911 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

22 Experts available now in Live!

Get 1:1 Help Now