I have a stored procedure that is run every night which is supposed to send the results of a query to several recipients. However on most days it ends up sending a duplicate email a minute later. The code I am using is as follows (all emails and database refs have been changed):
EXEC msdb.dbo.sp_send_dbmail
@recipients = 'email1@email.com',
@copy_recipients = 'email2@email.com;email3@email.com;email4@email.com',
@subject = 'Example Email',
@profile_name = 'ExampleProfile',
@query = 'SELECT name
FROM table
WHERE date BETWEEN (getdate() - 1) AND getdate()',
@attach_query_result_as_file = 1
Any help with this would be greatly appreciated.