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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 compare 2 table columns & update 3rd & 4th column
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

RiyaSen845
Starting Member

3 Posts

Posted - 12/12/2013 :  20:41:44  Show Profile  Reply with Quote
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)

Singapore
17689 Posts

Posted - 12/12/2013 :  20:46:22  Show Profile  Reply with Quote

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



KH
Time is always against us

Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.04 seconds. Powered By: Snitz Forums 2000