Case Else (SQL Server 2000)

Is it possible to make this query shorter

select v.temper,v.finish_id,v.grade,weight,
       case when v.thick between 0.17 and 0.209 then '1720' else
       case when v.thick between 0.21 and 0.229 then '2122' else
       case when v.thick between 0.23 and 0.279 then '2327' else
       case when v.thick between 0.28 and 0.359 then '2835' else
       case when v.thick between 0.36 and 0.399 then '3640' else
       case when v.thick between 0.40 and 99999 then '4099' end end end end end end
from v_mkt_stock_etlcoil v




MateenAsked:
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.

KarinLoosCommented:

select v.temper,v.finish_id,v.grade,weight,
       case when v.thick between 0.17 and 0.209 then '1720'
              when v.thick between 0.21 and 0.229 then '2122'
              when v.thick between 0.23 and 0.279 then '2327'
              when v.thick between 0.28 and 0.359 then '2835'
              when v.thick between 0.36 and 0.399 then '3640'
              when v.thick between 0.40 and 99999 then '4099' end
from v_mkt_stock_etlcoil v
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
hkamalCommented:
First of, you don't need to repeat the CASE; viz:
select v.temper,v.finish_id,v.grade,weight, case
       when v.thick between 0.17 and 0.209 then '1720'
       when v.thick between 0.21 and 0.229 then '2122'
       when v.thick between 0.23 and 0.279 then '2327'
       when v.thick between 0.28 and 0.359 then '2835'
       when v.thick between 0.36 and 0.399 then '3640'
       when v.thick between 0.40 and 99999 then '4099' end
from v_mkt_stock_etlcoil v

Only other way of doing this [especially if you use these values again] is to store them in a temp table  and join it to v_mkt_stock_etlcoil

select v.temper,v.finish_id,v.grade,weight, l.value
from v_mkt_stock_etlcoil v, limits l
where v.thick between l.low_limit and l.high_limit

HTH
0
MateenAuthor Commented:
Hi Karinloos:

select v.temper,v.finish_id,v.grade,weight,
       case v.thick
       when 0.21  then '2122'
       when 0.23  then '2327'
       when 0.28  then '2835'
       when 0.36  then '3640'
       when 0.40  then '4099' end
from   v_mkt_stock_etlcoil v
here column(v.thick) is referred one time. Is it not possible in my question query?
0
KarinLoosCommented:
Hi Mateen the above is valid, but in your original question you were querying v.thick to a range.

0
OtanaCommented:
If there are no other possibilities then the ones you specified, you could change the last line:

select v.temper,v.finish_id,v.grade,weight,
       case when v.thick between 0.17 and 0.209 then '1720'
              when v.thick between 0.21 and 0.229 then '2122'
              when v.thick between 0.23 and 0.279 then '2327'
              when v.thick between 0.28 and 0.359 then '2835'
              when v.thick between 0.36 and 0.399 then '3640'
              else '4099' end
from v_mkt_stock_etlcoil v
0
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

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.