Update all the records in a table using a sp

0

You have a table with column salary , and column bonus .

The salary column has numeric data, the bonus column is a numeric type but it is empty.

It is possible to create a stored procedure through which you can insert data to the whole bonus column, a percentage of the salary (taking as a condition ranges example: salaries from 1000 to 2000 50%, from 2001 to 5000 30%, higher of 5000 20%) ??

    
asked by Sikko 03.11.2018 в 01:44
source

1 answer

0

Yes, you could make a query like this and even put it in a stored procedure:

UPDATE miTabla
SET bonificacion =
    CASE
        WHEN sueldo BETWEEN 1000 AND 2000 THEN sueldo * .5
        WHEN sueldo BETWEEN 2001 AND 5000 THEN sueldo * .3
        WHEN sueldo > 5000 THEN sueldo * .2
        ELSE 0
    END

Good luck!

    
answered by 03.11.2018 / 01:50
source