Solved

Oracle SQL - Case Expression

Posted on 2011-02-14
3
363 Views
Last Modified: 2012-05-11
I need assistance in processing a table with the columns of departmetn_id, last_name, salary where the following condiions apply: - New column called "New Salary"

Must use Case expression

When department_id is 10 then 1.25 *salary
When department_id is 90 then 1.50*salary
When department_id is 130 then 1.75* salary
Otherwise display the old salary

0
Comment
Question by:dc0819
[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
3 Comments
 
LVL 28

Assisted Solution

by:Naveen Kumar
Naveen Kumar earned 250 total points
ID: 34893965
try this :

select department_id, last_name, salary,
case
when department_id = 10 then 1.25 * salary
when department_id = 90 then 1.50 * salary
when department_id = 130 then 1.75 * salary
else salary end "New Salary"
from your_table;

0
 
LVL 13

Accepted Solution

by:
riazpk earned 250 total points
ID: 34893991
Alternatively, you can also use:
SELECT department_id, last_name, salary,
 CASE department_id
   WHEN 10 THEN salary*1.25
   WHEN 90 THEN salary*1.50
   WHEN 130 THEN salary*1.75
   ELSE salary
 END "NEw Salary"
FROM <Table Name>

Open in new window

0
 
LVL 32

Expert Comment

by:awking00
ID: 34896958
You might consider using decode instead of case. See attached.
query.txt
0

Featured Post

Major Incident Management Communications

Major incidents and IT service outages cost companies millions. Often the solution to minimizing damage is automated communication. Find out more in our Major Incident Management Communications infographic.

Question has a verified solution.

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

Configuring and using Oracle Database Gateway for ODBC Introduction First, a brief summary of what a Database Gateway is.  A Gateway is a set of driver agents and configurations that allow an Oracle database to communicate with other platforms…
'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
This video shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…

734 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