Link to home
Start Free TrialLog in
Avatar of jaxrpc
jaxrpc

asked on

SQL

i have a table employee and i have 2 fields in it
EmployeeID number(8)
Salary number(7,2)

how do i increase the salary by +20 to all employee whose ID is an odd number.

thanks
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

this looks like homework, so you need to know that we cannot do the homework for you, but guide you.

there are several elements:
* do you know how to run an update in general?
* do you know how to formulate an update of a column?
* what is an odd number? -> what function/math/formula can you use (depends on the database products, refer to the function list...)
* limit the update to the above clause (odd number)
Avatar of jaxrpc
jaxrpc

ASKER

Yes i do know how to run an update statement
Yes i can formulate an update of a cloumn.
Odd number i would use employeeID % 2 if it is an odd it should give me a non zero.

update Employee set (salary = (select salary from employee where employeeID % 2 <> 0) + 30))

something like this? i tried ..

Avatar of jaxrpc

ASKER

update Employee set (salary = (select salary from employee where employeeID % 2 <> 0) + 30)) WHERE employeeID %2 <> 0

ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jaxrpc

ASKER

hi i tried your solutioon..but it says % is an invalid character...weird.
because oracle does not know the % as operator (like ms sql server does).

check out the modulus function:
http://www.psoug.org/reference/number_func.html
small correction: syntax should be:

UPDATE employee
SET salary = salary +30
WHERE ...
actually, +20 and not +30, as we all meanwhile wrote :-)