Hi
I have built a proc which basically captures some invalid codes and what I would like to do is use a trigger to fire an email everytime this the table receives information .
;WITH MatchesCTE ( SK_Partial, Matchcode ) AS
(SELECT 1, '1234')
SELECT * INTO match FROM MatchesCTE
ALTER TRIGGER EmailInavildPartials1
ON [dbo].[match]
AFTER INSERT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
IF (@@rowcount > 1)
SET NOCOUNT ON;
--SELECT GETDATE() ;
EXEC Send_email_Invalid_Partials1
END
ALTER PROCEDURE [dbo].[Send_email_Invalid_Partials1]
AS
DECLARE @p_body as nvarchar(max), @p_subject as nvarchar(max)
DECLARE @p_recipients as nvarchar(max), @p_profile_name as nvarchar(max), @p_query as nvarchar(max),
@p_subject_date as nvarchar(max), @fileName as nvarchar(max)
SET @p_profile_name = N'DEV'
SET @p_recipients = N'ROBERT@BLAH;'
Select @p_subject_date = (select DATENAME (weekday, getdate ()))+ ' ' + substring (convert(varchar,getdate(),12), 5,2) +'/' + substring (convert(varchar,getdate(),12), 3,2)+ '/' +
substring (convert(varchar,getdate(),12), 1,2)
SET @filename = 'INVALID MATCH CODES ' + CONVERT(CHAR(8),GETDATE(),112)+ '.csv'
SET @p_subject = @p_subject_date + N' INVALID MATCH CODES'
SET @p_body = 'Please see the invaild Partials List.'
SET @p_query = 'SET NOCOUNT ON;Select * FROM DATABASE..match '
EXEC msdb.dbo.sp_send_dbmail
@profile_name = @p_profile_name,
@recipients = @p_recipients,
@body = @p_body,
@body_format = 'HTML',
@subject = @p_subject,
@query = @p_query,
@attach_query_result_as_file = 1,
@importance = 'High',
@query_attachment_filename =@filename,
@query_result_separator = ',',
@query_result_no_padding = 1
you''ll need to change
@p_profile_name
@p_recipients
@p_query
when you then run the following
INSERT INTO match
SELECT 1,'1234'
UNION
SELECT 1, '5678'
It locks. Is there any way around this ? Any help would be great
Thanks