Skip to content

Instantly share code, notes, and snippets.

@HainanZhao
Created March 31, 2021 09:07
Show Gist options
  • Select an option

  • Save HainanZhao/9ca86f3db9b7693425800d03b573766e to your computer and use it in GitHub Desktop.

Select an option

Save HainanZhao/9ca86f3db9b7693425800d03b573766e to your computer and use it in GitHub Desktop.
Send Email in SQL server
begin
exec msdb.dbo.sp_send_dbmail
@profile_name = 'EMAIL_PROFILE',
@recipients = 'test@mailinator.com',
@subject = 'email subject',
@query = 'select * from table_name',
@attach_query_result_as_file = 1,
@query_result_header = 1,
@query_attachment_filename = 'data.csv'
End
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment