我在这里的第一篇文章,也是 SQL Server 的新手
我之前写过几个触发器,这个似乎不起作用。它是我的嵌套选择吗?我没有收到任何错误。只是没有通过电子邮件发送。
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
任何帮助将不胜感激
谢谢