I am trying to setup a trigger that sends an email if a field is changed to specific data. The trigger works when ever the field is changed, but I only need an email if the field is changed to 'In Review'
Any help is greatly appreciated.
-- Create the trigger
CREATE TRIGGER reviewntc
--indicate which table the trigger is to be executed on
ON CltDue
--indicate that this an UPDATE Trigger
FOR UPDATE
AS
IF UPDATE(CDSTATUS )
BEGIN
--holds the changes
declare @CDStatus varchar(40), @CDClientName varchar (40), @CDEventDesc varchar (40)
--grabs the data that we need
SELECT @CDStatus = CDStatus, @CDClientName = CDClientName, @CDEventDesc = CDEventDesc
FROM inserted
declare @rc int, @mymessage nvarchar(4000), @mysubject varchar (4000)
SET @mymessage = N'The '+@CDClientName +' "'+@CDEventDesc +'" project has been changed to '+@CDStatus+''
exec @rc = master.dbo.xp_s mtp_sendmail
@FROM = N'sender@domain .com',
@FROM_NAME = N'sender',
@TO = N'rcpt@domain.c om',
@subject = N'A project has been changed to "In review"',
@message = @mymessage,
@type = N'text/plain',
@server = N'email serverl'
select RC = @rc
END
go
Any help is greatly appreciated.
-- Create the trigger
CREATE TRIGGER reviewntc
--indicate which table the trigger is to be executed on
ON CltDue
--indicate that this an UPDATE Trigger
FOR UPDATE
AS
IF UPDATE(CDSTATUS )
BEGIN
--holds the changes
declare @CDStatus varchar(40), @CDClientName varchar (40), @CDEventDesc varchar (40)
--grabs the data that we need
SELECT @CDStatus = CDStatus, @CDClientName = CDClientName, @CDEventDesc = CDEventDesc
FROM inserted
declare @rc int, @mymessage nvarchar(4000), @mysubject varchar (4000)
SET @mymessage = N'The '+@CDClientName +' "'+@CDEventDesc +'" project has been changed to '+@CDStatus+''
exec @rc = master.dbo.xp_s mtp_sendmail
@FROM = N'sender@domain .com',
@FROM_NAME = N'sender',
@TO = N'rcpt@domain.c om',
@subject = N'A project has been changed to "In review"',
@message = @mymessage,
@type = N'text/plain',
@server = N'email serverl'
select RC = @rc
END
go
Comment