Quote:
It works if
Select EmpNo, EmpName, Salary
from employee
where EmpNo > 1000
order by
case when :sort-by-name = 'y'
then EmpName
else Salary
end
|
Apart from your issue, was it really worked?
Because, usually EmpName must be CHAR or VARCHAR and Salary must be number.
See
Numeric in
Rules for result data types - IBM DB2 9.7 for Linux, UNIX, and Windows
Quote:
Code:
If one operand is… And the other operand is… The data type of the result is…
...
...
INTEGER String DECFLOAT(34)
...
DECIMAL(w,x) String DECFLOAT(34)
|
So, result datatype must be DECFLOAT and most EmpName may not be able to convert to DECFLOAT.
I guessed that you may want to replace "else Salary" to "else CHAR(Salary)".
Anyhow, please try...
Code:
SELECT EmpNo, EmpName, Salary
FROM employee
WHERE EmpNo > 1000
ORDER BY
CASE
WHEN :sort-by-name = 'y' THEN
EmpName
ELSE CHAR(Salary)
END
, EmpNo
;