2013-08-06 156 views
2

我想從一個表格更新數據到另一個具有年份條件的表格。使用SQL Server 2008從一個表格更新到另一個表格

UPDATE pgptrans 
SET dcamt1 = t2.ecamt1 
FROM pgptrans t1 
INNER JOIN pgptrans060713 t2 ON t1.empcode = t2.empcode 
WHERE  
    t1.empcode LIKE '130%' 
    AND t1.yrmn = '201308' 
    AND t2.yrmn = '201207' 

這裏更新pgptrans表(到年201307)從pgptans060713ecamtdcamt(從今年應該是201308)與empcode開始從130

請幫我

thanx提前

shubha

回答

2
UPDATE t1 
SET t1.dcamt1 = t2.ecamt1 
FROM pgptrans t1 
INNER JOIN pgptrans060713 t2 ON t1.empcode = t2.empcode 
WHERE t1.empcode LIKE '130%' 
    AND t1.yrmn = '201308' 
    AND t2.yrmn = '201207' 
+0

+1 - 爲好答案。 – Devart

+0

@Devart謝謝您的編輯.. –

+0

不客氣@Amit Singh :) – Devart

0

更新基於內部採用另一個表一個表連接

UPDATE t1 SET 
     t1.status = 1 
FROM table1 t1 
     INNER JOIN table t2 
        ON t1.Id = t2.ID 
WHERE t2.num = 15 
相關問題