傳送查詢結果
這會附加查詢 SELECT * FROM Users
的結果並將其傳送到 recipient@someaddress.com
EXEC msdb.dbo.sp_send_dbmail
@profile_name = 'The Profile Name',
@recipients = 'recipient@someaddress.com',
@query = 'SELECT * FROM Users',
@subject = 'List of users',
@attach_query_result_as_file = 1;