DECLARE @temp AS TABLE (id INT NOT NULL PRIMARY KEY CLUSTERED, name VARCHAR(10))
BEGIN TRY
declare @Source table (id int not null, name varchar(10))
insert @Source
SELECT 11,'ABC' union all
SELECT 12,'CDE' union all
SELECT 13,'FGH' union all
SELECT 11,'IJK'
INSERT INTO @temp
SELECT * from @Source
SELECT * FROM @temp
END TRY
BEGIN CATCH
EXEC msdb.dbo.sp_send_dbmail
@profile_name = 'Profile Name',
@recipients = 'email@email.com',
@body = Error_Message,
@subject = Error_Message ;
END CATCH;
GO
这是我的代码工作正常.. 但我想在邮件中包含的是 ID,它导致错误作为对某些电子邮件 ID 的提醒,在这种情况下它是“11”。我怎样才能以某种聪明的方式做到这一点..?