I have a update query something like
update employees
set salary = salary - (select sum(salary) from employees where manager_id in (101,102))
where employee_id = 105;
The sql above works fine but the below sql is updating NULL instead of value.
UPDATE table1 a
SET a.col1 = a.col1 - (SELECT SUM(b.col2)
FROM table2 b
WHERE b.col3 = 'AA'
AND b.col4 = '1234'
AND b.col5 = '123456789'
AND b.col6 = 'O'
AND b.col7 IN ( 1, 2, 3, 4 ))
WHERE a.col3 = 'AA'
AND a.col4 = '2313'
AND a.col5 = '987654321';
Do someone know the reason?
Will it update NULL if salary values have some NULL values in them. (I know it wont because the inner query returns a number value).
It works fine if I hardcode the values for the inner query but fails if i use bind parameters. (However a numeric value is returned both when hardcoded or when bind parameter used. )
I just cant seem to know whats wrong with this simple query.
UPDATE TABLE1 a SET a.COL1 = a.COL1 - (SELECT SUM(b.COL2) FROM TABLE2 b WHERE b.COL3 = 'AA' AND b.COL4 = '1234' AND b.COL5 = '123456789' AND b.COL6 = 'O' AND b.COL7 IN (1,2,3,4) ) WHERE a.COL3 = 'AA' AND a.COL4 = '2313' AND a.COL5 = '987654321' ;