Wednesday, May 12, 2010

SQL/PL Update Statement and Sub Update Statement Findings





OK. I have done the update using sub inner update statement as shown below.
But when ever code (A) is executed it crash in store procedure because the conditions are not meet and sql execute update statement.

(A)
update (select t1.field1, t2.field2
from table2 t2
where t1.field2 = t2.field2) myupdatedtable t3
set myupdatedtable.field1 = myupdatedtable.field2;

so I have changed to (B) this way it runs fine without any problem and does not crash.

(B)
update table1 t1
set t1.field1 = (select t2.field1
from table2 t2
where t1.field2 = t2.field2)
where exists (select t2.field1
from table2 t2
where t1.field2 = t2.field2) ;

Hope this helps!


No comments:

Post a Comment