I was trying to create a procedure which shows the absolute salary of an employee using a param, to do that I need how many children the employee has, this way:
If the salary is < 500 the absolute salary will be:
absoluteSalary = salary + numChildren * 200
Else:
absoluteSalary = salary + numChildren * 100
This is my code:
create procedure absoluteSalary (@documento varchar(8))
as
begin
select
nombre, apellido,
if (select sueldo from empleados) < 500
begin
sueldo + cantidadhijos*200
end
else
begin
sueldo + cantidadhijos*200
end as sueldototal
from
empleados
where
@documento like '%'
end;
But I have a mistake in this if, and I don't know why, my friend did this an it works:
create pa_sueldototal(@documento varchar(8)=’%’)
as
select
nombre, apellido,
sueldoTotal = case
when sueldo >= 500
then sueldo + (cantidadhijos * 100)
when sueldo < 500
then sueldo + (cantidadhijos * 200)
end
from
empleados
where
documento like @documento;