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)
 Update Statement

Author  Topic 

Brittney10
Posting Yak Master

154 Posts

Posted - 2012-03-13 : 11:39:27
I need to do an update statement based on the following:

I have TableA which contains ClientID, Name, and Number.

I also have TableB which contains ID, ClientID, and RegID

I also have TableC which contains RegID, Name, and Number.

(You can see the relationships is color).

What I need to be able to do, is update TableB based on the data in TableA (which is also in TableC bridge table- this data is pre-populated)

For example this what i would expect to see.

TableA
12345, CompanyABC, 5312

Table B
101112, 12345, 67890

Table C
67890, CompanyABC, 5312



Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2012-03-13 : 12:22:44
What would you use to join from TableA to TableC (Name and Number, Name or Number)?
Go to Top of Page

Brittney10
Posting Yak Master

154 Posts

Posted - 2012-03-13 : 12:24:38
Name and Number.
quote:
Originally posted by Lamprey

What would you use to join from TableA to TableC (Name and Number, Name or Number)?

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-03-13 : 15:49:00
[code]
insert into TableB(ClientID,RegID)
SELECT a.ClientID,c.RegID
FROM TableA a
INNER JOIN TableC c
ON c.Name = a.Name
and c.Number = a.Number
[/code]



------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -