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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problems with Select Case and Group By 1

Status
Not open for further replies.

goranm

Programmer
Dec 18, 2001
247
SE
Hello!

My question is if it is possible to have a "Select Case" with a SUM (or MAX) and the have a GROUP BY.

We have a alphanumeric field where there in some specified positions will be values for length, width and heigth.

I have to pick out the biggest value, but I also want to check and see if it´s a numeric value that is stored in the field.

But it´s seems to be a problem when I try to use it with a group by function.
Is it possible to do it, and how shall I then change my query?

My query looks just now like this:

Code:
SELECT
  COID,
  COPOS
  MAX(TRIM(SUBSTR(ROW.INSTRUCTIONS,112,9))) LENGTH,
  CASE
     WHEN LENGTH(TRIM(TRANSLATE (TRIM(SUBSTR(ROW.INSTRUCTIONS,130,9)), ' +-.0123456789',' '))) IS NULL THEN
        SUM(TRIM(SUBSTR(ROW.INSTRUCTIONS,130,9))) 
     ELSE
        SUM(0)
  END AS HEIGHT,
  SUM(TRIM(SUBSTR(ROW.INSTRUCTIONS,176,16))) WEIGHT
FROM
  ROW
GROUP BY
  COID,
  COPOS

Thanks in advance
/Goran
 
I suppose you should reverse CASE and SUM.
Untested, but something like:

Code:
SUM(
CASE
     WHEN LENGTH(.....)) IS NULL THEN
        TRIM(....))
     ELSE
        0 )
  END AS HEIGHT

hope this helps
 

oh, bracket in the wrong place, sorry:
ELSE
0
END ) AS HEIGHT
 
Thank you hoinz. It worked perfectly.

/Goran
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top