CASE sql

I need bit of help here if possible tell me how to do this .


i need to put this in one case

ID =    in (0510  ,0700 ,  0701)  and    0690 to 0692    and 0694 to 0698     and 0991 to 0992   and 1230 to 1231

Thanks .
Syed Ali Shah RashdiT24/Insight Technical ConsultantAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mike EghtebasDatabase and Application DeveloperCommented:
Case
When ID  in ('0510'  ,'0700' ,  '0701')  then 'A '
When ID Between(  '0690' and '0692') Then 'B'
When ID Between ('0694' and '0698') Then 'C'
When ID Between ('0991' and '0992') Then 'D'
When ID Between('1230' and '1231') Then 'E'
Else 'F' End As Result

Open in new window

0
Syed Ali Shah RashdiT24/Insight Technical ConsultantAuthor Commented:
that's different cases i need them all in one case.

Case when ID =    in (0510  ,0700 ,  0701)  and    0690 to 0692    and 0694 to 0698     and 0991 to 0992   and 1230 to 1231 then 'yes'
0
PortletPaulfreelancerCommented:
CASE
    WHEN ID  in ('0510'  ,'0700' ,  '0701')
        OR ID Between  '0690' and '0692'
        OR  ID Between '0694' and '0698'
        OR ID Between '0991' and '0992'
        OR ID Between '1230' and '1231'
        THEN 'yes'
    ELSE 'no'
END AS Result

{+edit]
sorry, OR's not ands, and removed parentheses after between
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

Mike EghtebasDatabase and Application DeveloperCommented:
correction:

Case
When ID  in ('0510'  ,'0700' ,  '0701')  then 'A '
When ID Between  '0690' and '0692' Then 'B'
When ID Between '0694' and '0698' Then 'C'
When ID Between '0991' and '0992' Then 'D'
When ID Between '1230' and '1231' Then 'E'
Else 'F' End As Result

No this is one case.
0
MlandaTCommented:
CASE
    WHEN ID  in (0510  ,0700 ,  0701) 
        OR ID Between  0690 and 0692
        OR ID Between 0694 and 0698
        OR ID Between 0991 and 0992
        OR ID Between 1230 and 1231
        THEN 'yes'
    ELSE 'no' 
END AS Result

Open in new window

Rather OR than AND
0
PortletPaulfreelancerCommented:
or, you can just list out the values to us a single IN()

CASE
    WHEN ID  in ('0510','0700','0701','0690','0691','0692','0694','0695','0696','0697','0698','0991','0992','1230','1231')
        THEN 'yes'
    ELSE 'no'
END AS Result
0
Mike EghtebasDatabase and Application DeveloperCommented:
try:
Case When ID in ('0510' ,'0700' , '0701')  or ID Between '0690' and '0692' or ID Between '0694' and '0698' or ID Between '0991' and  '0992' or ID Between '1230' and '1231' Then 'Yes' Else 'No' End As Result

Open in new window


edited
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2008

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.