December 14, 2006 at 10:33 am
Hi,
I have two tables in my SQL Database.
T1,
Date,Time,Customer, Value,Ref
T2
Date,Time,Customer, Value,Ref
I am looking for a way to update T2 when a value is inserted into T1, but the trigger would need to validate that the record does not already exist in T2.
Could you possiblt assist me with this ?
Thanks,
Amie
December 14, 2006 at 10:52 am
You could try something like:
if exists (select * from t2 t inner join inserted i
on t.Customer= i.Customer
and t.Value = i.Value)
begin
raiserror ('The value exists in t2', 16, 1)
rollback transaction
end
The "inserted" table indicates the records that are inserted by an insert query or updated by an update query.
Russel Loski, MCSE Business Intelligence, Data Platform
December 14, 2006 at 11:02 am
December 14, 2006 at 12:56 pm
Gentlemen,
Thankyou for your replies.
Russel,
Would your solution also work if an application updated the tables?
Nick
December 14, 2006 at 1:07 pm
It would if you put this in an update trigger. You can specify that the trigger is an update trigger or insert trigger or both.
Russel Loski, MCSE Business Intelligence, Data Platform
December 15, 2006 at 4:25 am
Hi
It is simply possible with Triggers as well as OUTOUT with using INSERT Statement.
There is smaple programe of using OUTPUT Clause.
|
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply