2013-02-15 62 views
1

我不得不從選我得到這個2代表與此行做更新更新來自SELECT

T1

customer_number | trx number  | amount_due_remaining 
____________________________________________________ 
309514   |MM1218881/2011 | 0 
309514   |MM1218882/2011 | 0 
309514   |MM1218903/2011 | 0 
309514   |MM1218905/2011 | 0 

T2

contract | numdoc   | import 
___________________________________ 
309514 |MM1218881/2011 | 2000,77 
309514 |MM1218882/2011 | 1000,45 
309514 |MM1218903/2011 | 1000,23 
309514 |MM1218905/2011 | 2500,12 

我必須把在T2中,將列的數量T1的值amount_due重新導入進口

我這樣做查詢

update dbestrconto T1 
SET T1.IMPORTO = (
SELECT nvl(T2.AMOUNT_DUE_REMAINING,0) 
FROM [email protected] T2 
WHERE T2.customer_number=T1.contratto 
AND T2.customer_number='3095614' 
and T2.TRX_NUMBER=T1.NUMDOC 
) 

,但錯了,請幫助我。

問候,魯道夫

回答

0

要更新所有行 - 你需要添加到您更新where子句。

我會推薦使用MERGE代替。

merge into dbestrconto t1 
using [email protected] t2 
on (t2.customer_number=t1.contratto 
and t2.trx_number=t1.numdoc) 
when matched then update set 
    t1.importo = nvl(t2.amount_due_remaining,0) 
where t2.customer_number='3095614'; 

問候。 HAKI。