Sql server Trigger insert value into one table from two difference tables?
I have these tables tbl_Users, tbl_prepaid, and tbl_Expire.
I am using a trigger on tbl_Prepaid that deletes the card number from
tbl_Prepaid and inserts it into tbl_Expire immediately after entry.
Now I want to move userID from tbl_Users into tbl_Expire in the same trigger.
How I can do it?
Here is what I have so far:
alter TRIGGER trgAfterUpdate ON [dbo].[tbl_Prepaid]
FOR UPDATE
AS
declare @id_ppaid int;
declare @serial nvarchar(100);
declare @balance nvarchar(100);
declare @price int;
select @id_ppaid=i.id from inserted i;
select @serial=i.serial from inserted i;
select @balance=i.balance from inserted i;
select @price=i.price from inserted i;
if update(used)
insert into tbl_Expire(id_Pripaid,serial,balance,price)
values(@id_ppaid,@serial,@balance,@price);
delete from tbl_Prepaid where id=@id_ppaid;
PRINT 'After updates trigger fired.'
GO
No comments:
Post a Comment