Email Trigger failing in SQL Server 2012

345340 pts.
Tags:
SQL Server 2012
SQL Trigger
I'm having trouble getting a trigger to work.No errors are being thrown, but nothing is being email either. Is it my nested select?
Use ABCTRAINING

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

alter TRIGGER TAXPERCENT
   ON  [dbo].[AP101_VOUCHER_DISTR] AFTER update AS 

declare @VAT numeric(15,2),
@Total numeric(15,2),
@VATPERCENT numeric(15,2),
@Voucher nvarchar(max),
@AMT numeric(15,2),
@GL numeric(15,2)

Select @Voucher = i.ap101_voucher,
@AMT = i.ap101_amt,
@GL = i.AP101_GL_ACCT,
@VAT = (select sum(iif(@GL = '70102501110' or @GL = '70102501120',@AMT,0))),
@Total = (select sum(@AMT)),
@VATPERCENT = @VAT/(@Total-@VAT)
from inserted i

if @VATPERCENT <> 0.140

BEGIN
DECLARE @msg nvarchar(MAX)
Declare @Subj varchar(MAX)
Declare @EM nvarchar(MAX)
SET @msg = 'The VAT on this Voucher ' + @Voucher + ' ' + 'does not equal 14% ' + ' ' + @VATPERCENT
SET @Subj = 'Voucher Error'
set @EM = 'xxxxxx@company.co.za'

EXEC msdb.dbo.sp_send_dbmail 
@importance ='High',
@recipients=@EM,
@body= @msg,
@subject = @Subj,
@body_format = 'HTML',  
@profile_name = 'ABC Profile'
END

Answer Wiki

Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Discuss This Question:  

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following