Home » SQL & PL/SQL » SQL & PL/SQL » Assign column Value to another variable
Assign column Value to another variable [message #321441] Tue, 20 May 2008 05:07 Go to next message
kathiresan.c
Messages: 23
Registered: February 2008
Location: Tamil Nadu, India
Junior Member
Hi friends,

I want to do with small calculation in sql query itself..

That is

I have a salary column in a table..
when retrieving value of salary column from the table i want to add 10% hike of the salary and i want to display hiked % value also..

I wrote a query

select salary+(salary*10) as "New Salary", salary*10 "Hiked Value" from employees;

This query executes fine but i want to get hike value from (New Salary - salary).. i tried but the alias name cant used to arithmetic operation..

is any other solution for this problem?



Re: Assign column Value to another variable [message #321444 is a reply to message #321441] Tue, 20 May 2008 05:10 Go to previous messageGo to next message
Frank
Messages: 7880
Registered: March 2000
Senior Member
Push the initial calculation away into a subquery
Re: Assign column Value to another variable [message #321471 is a reply to message #321441] Tue, 20 May 2008 06:28 Go to previous messageGo to next message
seyed456
Messages: 220
Registered: May 2008
Location: south india .
Senior Member

instead of alias u write. ..
select salary+(salary*.1)-salary as hike
from emp

then u will get a hiked amount .. .

[Updated on: Tue, 20 May 2008 06:29]

Report message to a moderator

Re: Assign column Value to another variable [message #321473 is a reply to message #321471] Tue, 20 May 2008 06:38 Go to previous message
Michel Cadot
Messages: 64106
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
@seyed456,

Please read OraFAQ Forum Guide, especially "How to format your post?" and "Posting guidelines" sections.

"u" is not a member of this forum.

Regards
Michel

Previous Topic: UTL_FILE: Need to reinitialize the file pointer to first position
Next Topic: insert query results into a table
Goto Forum:
  


Current Time: Mon Dec 05 03:06:45 CST 2016

Total time taken to generate the page: 0.10403 seconds