Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL table update problem

Status
Not open for further replies.

Gregv1506

IS-IT--Management
Nov 9, 2006
3
CA
Hi,

I have 2 tables and I want to update Table_2 with fields from Table_1.

Table_1 has the following fields
Client_Nr
Name
Address
City

Table_2 has the following fields
Client_Nr
Name
Address
City

Table_2 has records where the Name, Address and City fields are empty.
Client_Nr is filled in both tables.
What is the easiest way:
- to update the records in Table_2 where Name, Address and City are Nill?
- to update all records?

Thanks,

Greg
 
Code:
update table2
   set Name = B.Name
     , Address = B.Address
     , City = B.City
  from table2 A
inner
  join table1 B
    on B.Client_Nr = A.Client_Nr
 where A.Name is null
   and A.Address is null
   and A.City is null
remove the WHERE clause to update all rows

r937.com | rudy.ca
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top