Я пытаюсь создать базу триггеров для отправки электронной почты для каждого пользователя в каждой записи, созданной/вставленной в мою таблицу, так как у меня уже есть путь в DB ниже моего кода, пожалуйста если кто-нибудь может мне помочь в этомтриггер для отправки почты при вставке записи в формате PDF
CREATE TRIGGER DP_READY
ON dbo.TimesheetLog
for insert
AS
declare @pdf nvarchar (max)
declare @email nvarchar (50)
declare @fcode nvarchar (50)
declare @date date
set @pdf= (select distinct 'C:\Papyrus_Router\Output\PDF' + '\' + a.cpdffilename AS pdf_f , b.Name,b.cforeman, b.Email
from timesheetlog as a left join EmailSubscription b on right(ltrim(rtrim(a.cheaderkey)) ,6)= b.cforeman
where cstatus = 'DP-READY')
set @email= (select distinct b.Email
from timesheetlog as a left join EmailSubscription b on right(ltrim(rtrim(a.cheaderkey)) ,6)= b.cforeman
where cstatus = 'DP-READY')
set @fcode = (select distinct b.cforeman +'-'+ b.Name+'-'+ convert(varchar(50),convert(date,a.dcreated))
from timesheetlog as a left join EmailSubscription b on right(ltrim(rtrim(a.cheaderkey)) ,6)= b.cforeman
where cstatus = 'DP-READY')
SET NOCOUNT ON;
set @date = (select distinct convert(date,a.dcreated)
from timesheetlog as a left join EmailSubscription b on right(ltrim(rtrim(a.cheaderkey)) ,6)= b.cforeman
where cstatus = 'DP-READY')
-- Insert statements for trigger here
if CHARINDEX(@pdf, @email) > 0 and @date = getdate()
BEGIN
EXEC msdb.dbo.sp_send_dbmail
@[email protected],
@file_attachments = @pdf,
@subject = @fcode,
@body = 'Your Sync data from the Pens '
END
GO
утра получаю эту ошибку
Only one expression can be specified in the select list when the subquery is not introduced with EXISTS.
установить переменные, как: выберите @ PDF = 'C: \ Papyrus_Router \ Output \ PDF' + '\' + a.cpdffilename из timesheetlog, как левое соединение EmailSubscription b справа (ltrim (rtrim (a.cheaderkey)), 6) = b.cforeman , где cstatus = 'DP-READY' –