SQL Server provides an easy way to email the results of a query to yourself (or to someone else).
To send email with T-SQL, you need to use the sp_send_dbmail
stored procedure in the msdb database. This procedure accepts many arguments, one of which is the @query
argument. That’s the argument that attaches the results of your query to the email.