?
Solved

Oracle SQL - Case Expression

Posted on 2011-02-14
3
Medium Priority
?
370 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 1000 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 1000 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

Stack Overflow Podcast - Developer Story

Welcome to the Stack Overflow podcast recorded Thursday July 20 at Stack Overflow Headquearters in NYC. Your hosts today are podcast regulars Jay Hanlon, David Fullerton, and Ilana Yitzhaki, plus the quite irregular Matt Sherman (Stack Overflow Engineering Manager extraordinaire)

Question has a verified solution.

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

Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.
Via a live example, show how to take different types of Oracle backups using RMAN.
Suggested Courses

800 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