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
 General SQL Server Forums
 New to SQL Server Programming
 compare rows in sql 2000

Author  Topic 

l-jeff@excite.com
Starting Member

39 Posts

Posted - 2008-05-22 : 10:39:35
i have two tables. 1st table gets the information from as400, then moves the data to table 2 at sql 2000 server. I need to see when as400 updates\changes or inserts new information to table 1 how to update\change or insert into table 2?

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-05-22 : 10:41:29
You could make a trigger on table1.



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

l-jeff@excite.com
Starting Member

39 Posts

Posted - 2008-05-22 : 10:50:01
how do i do that? i read info on triggers and can't get it to work.

Lisa Jefferson
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-05-22 : 11:26:48
quote:
Originally posted by l-jeff@excite.com

how do i do that? i read info on triggers and can't get it to work.

Lisa Jefferson


Write a trigger on table 1 for UPDATE,DELETE, INSERT

It will be something like

CREATE TRIGGER table_IUD ON table1
AFTER INSERT,UPDATE,DELETE
AS
BEGIN

IF EXISTS (SELECT * FROM INSERTED)
AND NOT EXISTS(SELECT * FROM DELETED)
BEGIN
INSERT INTO table2
SELECT your fields
FROM INSERTED i
END

IF EXISTS (SELECT * FROM INSERTED)
AND EXISTS(SELECT * FROM DELETED)
BEGIN
UPDATE t
SET t.field1=i.field1,t.field2=i.field2,...
FROM table2 t
INNER JOIN INSERTED i
ON i.FKCol=t.PKCol
END

IF NOT EXISTS (SELECT * FROM INSERTED)
AND EXISTS(SELECT * FROM DELETED)
BEGIN
DELETE t
FROM table2 t
INNER JOIN DELETED d
ON d.FKCol=t.PKCol
END

END

Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2008-05-22 : 11:45:14
How frequently do you need to see the changes?

Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page
   

- Advertisement -