Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Oracle SQL - Case Expression

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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

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 …
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.

636 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