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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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

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'
PortletPaulEE Topic AdvisorCommented:
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
Protecting & Securing Your Critical Data

Considering 93 percent of companies file for bankruptcy within 12 months of a disaster that blocked access to their data for 10 days or more, planning for the worst is just smart business. Learn how Acronis Backup integrates security at every stage

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.
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
PortletPaulEE Topic AdvisorCommented:
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
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

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.