First back up and look at this line.
"set dept=' ' where id in (select id from lookup) and sal in (select sal from lookup) "
This looks to see if the ID is in the lookup, and then looks to see if the sal is in the lookup. It DOES NOT look to see if the ID and SAL are associated.
SO id = 1, SAL = 300 Will match if 2 records exist such as ID = 1, SAL = 200 and ID = 3, SAL = 300
Just add a case block for each condition and assign, there is no need to go through the data more than once.
... View more