user1702346
user1702346

Reputation: 119

Update from one table to another table using SQL Server 2008

I want to update data from one table to another table with year condition.

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'

Here update dcamt of pgptrans table (to yr 201307) from ecamt of pgptans060713 (from year should be 201308) with empcode starts from 130

please help me

thanx in advance

shubha

Upvotes: 2

Views: 4134

Answers (2)

kavitha Reddy
kavitha Reddy

Reputation: 3333

To Update one table based on another table using INNER JOIN

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

Upvotes: 0

Amit Singh
Amit Singh

Reputation: 8109

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'

Upvotes: 2

Related Questions