Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ORDER BY CASE

Status
Not open for further replies.

jmennen

Programmer
Aug 5, 2003
2
US
How would I change this query that I am running from my servlet so that it takes out the duplicates of B and R just like it is currently doing, but then also combines E and V and removes their duplicates and orders them by E then V? I can add them together with the following code, but cannot order them separately. Any ideas? The order should be B, R, E, V with B and R unioned and E and V unioned but seperated in the order. Currently it is B and R bunched together followed by E and V bunched together. E needs to come before V.

SELECT DISTINCT
a.itemtype
, c.textid
, c.min
, c.max
, rtrim(c.header) as header
, CASE a.itmlabel
WHEN 'B' THEN 1
WHEN 'R' THEN 1
WHEN 'E' THEN 2
WHEN 'V' THEN 2
END ORDERING_COLUMN FROM
RTC_global.productLibrary.vdepts d
, RTC_global.productLibrary.item a
, RTC_global.productLibrary.text c
WHERE
a.priceapproved = 'Y'
AND d.deptcode = -- tempInt.parseInt(dept[0])
AND d.classcode = -- tempInt.parseInt(classCode[0])
AND d.subcode = -- tempInt.parseInt(subCode[0])
AND a.dept = d.dept
AND a.subdept = d.subdept
AND a.class = d.class
AND a.subclass = d.subclass
AND a.textid = c.textid
AND c.status = 'A' ORDER BY ORDERING_COLUMN

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top