我有一个在填充表格的xml语句中收到的表单消息。
我写了一个触发器,通过db-mail向内部人员发送一条表单消息。
触发器有效,但触发器的EXE返回所有记录,而不仅仅是插入的记录
CREATE TRIGGER dbo.ServRequestEmail
ON schema.dbo.form91415ib
for INSERT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
DECLARE @BODY NVARCHAR(MAX) = N'';
DECLARE @SUBJECT NVARCHAR(40) = N'';
SELECT @SUBJECT += CHAR(5) + 'MAINTENANCE REQUEST FROM TRUCK ' + vehicle_number FROM INSERTED;
SELECT @BODY += CHAR(13) + CHAR(10) + Left(driver_id, 15) + 'IN TRUCK' + vehicle_number + ' AT '+ created_datetime
+ ' REQUESTED SERVICE ON THE ' + Left(service_on, 7) + 'FOR A SERVICE TYPE OF ' + Left(service_type, 20) + 'AT THE LOCATION OF '
+ Left(inroute_city, 30) + 'BECAUSE A SERVICE OF ' + pm_type_due + 'IS DUE. THE DRIVER ADDED THESE REMARKS: ' + remarks
+ ' The driver was located '+ Left(auto_location, 40) + ' when they sent the message in' FROM INSERTED;
IF EXISTS (SELECT 1 FROM INSERTED WHERE vehicle_number IS NOT NULL)
BEGIN
EXEC msdb.dbo.sp_send_dbmail
@TO = 'sendto@ouremail.COM',
@PROFILE_NAME = 'MAINTENANCE NOTIFICATIONS',
@SUBJECT = @SUBJECT,
@BODY = @BODY;
END
END
GO
为什么我会返回表schema.dbo.form91415ib中的所有记录而不仅仅是Inserted记录?