I have two table data and data1
data has two coloumns student id and marks
i need to create trigger which will update marks from data and will display marks into data1 with 4 coloumns
studntid, new_marks,old_marks,date
i have written a code but it is not showing old marks it just updates new marks and rest fileds.
CREATE TRIGGER marksss
ON [dbo].[data] after UPDATE
AS
declare @studentid int;
declare @marks int;
declare @xyz int;
declare @newmarks int;
declare @oldmarks int;
select @studentid=i.student_id from inserted i; --to fetch inserted values
select @marks=i.marks from inserted i;
begin
if update(marks)
--set @oldmarks=@mark
set @newmarks=@marks
insert into data1(student_id,new_marks,old_marks,date)
values (@studentid,@newmarks,@oldmarks,getdate());
end
go