Randomuser1204281 Randomuser1204281 - 4 years ago 72
SQL Question

Replace field with a custom one [ORACLE]

Problem:
I need to translate some errors into a select statement.

Example:
I have a table with the following information:

-----------------------
|ID | NAME | ERROR|
|-----------------------|
| 001 | example1 | err1 |
| 002 | example2 | err2 |
| 003 | example3 | err3 |
-----------------------


Every mistake means:

err1: Login failed
err2: Failure of the database
err3: Hard drive full


I need to make a select statement that returns the information as follows:

-----------------------------------------
|ID | NAME | ERROR |
|-----------------------------------------|
| 001 | example1 | Login failed |
| 002 | example2 | Failure of the database|
| 003 | example3 | Hard drive full |
-----------------------------------------


My intent
: I've tried the following:

SELECT *,
CASE
WHEN error=err1 THEN 'Login failed'
WHEN error=err2 THEN 'Failure of the database'
WHEN error=err3 THEN 'Hard drive full'
END
FROM table;

Answer Source
SELECT table.*,
CASE
  WHEN error=err1  THEN 'Login failed'
  WHEN error=err2  THEN 'Failure of the database'
  WHEN error=err3  THEN 'Hard drive full'
END as NEW_ERROR
FROM table
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download