?
Solved

Case Else (SQL Server 2000)

Posted on 2005-03-11
5
Medium Priority
?
455 Views
Last Modified: 2008-03-06
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




0
Comment
Question by:Mateen
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 13

Accepted Solution

by:
KarinLoos earned 2000 total points
ID: 13515627

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
 
LVL 5

Expert Comment

by:hkamal
ID: 13515678
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
 

Author Comment

by:Mateen
ID: 13515924
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
 
LVL 13

Expert Comment

by:KarinLoos
ID: 13515970
Hi Mateen the above is valid, but in your original question you were querying v.thick to a range.

0
 
LVL 11

Expert Comment

by:Otana
ID: 13516023
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

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…
Suggested Courses

777 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