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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

UPDATE The Master Table Using The Imported Table

Status
Not open for further replies.

DDTiff

MIS
May 29, 2002
48
US
Hello Everyone,

Can someone please help me with the UPDATE SQL Query? I appreciate your time and effort in advance.

I have 2 tables in a db called "Master Table" and "Imported Table." Both tables have the same number of fields and field names as follow: UID, Name, Branch, Manager, Organization.

I would like to update the Master Table whenever Imported Table has updated data.

For example, when the existing records of the Imported Table WHERE [Imported Table].Branch="B1" are updated; I would like to update the existing records of the Master Table WHERE [Master Table].Branch="B1" WHERE [Master Table].UID=[Imported Table].UID.

Again, I thank you for your time and help in advance.

Tiff
 
Use the following sctipt as an example

create database junk
go
use junk
go
create table x(c1 int identity primary key,c2 char not null,c3 char not null)
create table y(c1 int primary key,c2 char not null,c3 char not null)
go
create trigger inX on x for insert
as
insert into y select * from inserted
go
create trigger upX on x for update
as
update y set y.c2 = i.c2, y.c3 = i.c3 from inserted i where i.c1 = y.c1
go
insert into x values('a','b')
insert into x values('a','c')
insert into x values('b','b')
insert into x values('c','b')
go
select * from x
select * from y
go
truncate table x
go
create proc addrows as
insert into x values('a','b')
insert into x values('a','c')
insert into x values('b','b')
insert into x values('c','b')
GO
UPDATE X SET C2 = 'W' ,C3 ='T' WHERE C1 IN (1,3,4)
go
select * from x
select * from y
go
drop database junk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top