Create Trigger while update Specific column of table

ALTER TRIGGER trgAfterContractDeedFileURLUpdate ON  [Contract]
FOR UPDATE
AS
begin
    declare @BusinessUnit nvarchar(50);
declare @newContractDeedUrl nvarchar(250);
declare @oldContractDeedUrl nvarchar(250);
    set @BusinessUnit = 'Insert To ContractDeedUrlHistory if Contract Deed URL is updated.'


select @newContractDeedUrl = ContractDeedUrl from inserted;

select @oldContractDeedUrl = ContractDeedUrl from deleted;

if(@newContractDeedUrl <> @oldContractDeedUrl)
begin
insert into
ContractDeedUrlHistory(ContractNo,ContractDate, OwnerID,ContractDeedUrl,Entry_By,Entry_Date)
SELECT
ContractNo,ContractDate, OwnerID,ContractDeedUrl,Entry_By,Entry_Date
FROM
deleted
end ;
     
end

Comments

Popular posts from this blog

How to use DbFunctions.TruncateTime

Provision AWS EC2 Instance and RDS with Terraform, and Deploy Spring Boot App to EC2 Instance via GitHub Action Pipeline

Microsoft Access Connectivity from C#