Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 compare 2 table columns & update 3rd & 4th column

Author  Topic 

RiyaSen845
Starting Member

3 Posts

Posted - 2013-12-12 : 20:41:44
I want to compare two table columns,get the common data and update the values of ID & Flag columns in to 3rd & 4th column of the 1st table

TABLE 1

------------------------------------
name fullname ID FLAG
------------------------------------
AAA AAAAAA NULL
BBB BBBBBB NULL
CCC CCCCCC NULL
DDD DDDDDD NULL
EEE EEEEEE NULL
FFF FFFFFF NULL

TABLE 2

------------------------------------
name fullname ID FLAG
------------------------------------
AAA AAAAAA 1 Y
BBB BBBBBB 2
DDD DDDDDD 4 Y
EEE EEEEEE 5 Y


RESULT OF TABLE 1


------------------------------------
name fullname ID FLAG
------------------------------------
AAA AAAAAA 1 Y
BBB BBBBBB 2
CCC CCCCCC NULL
DDD DDDDDD 4 Y
EEE EEEEEE 5 Y
FFF FFFFFF NULL


Could anyone please help on this?

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2013-12-12 : 20:46:22
[code]
UPDATE t1
SET ID = t2.ID,
FLAG = t2.FLAG
FROM TABLE1 t1 INNER JOIN TABLE2 t2 ON t1.name = t2.name and t1.fullname = t2.fullname
[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -