• You can also use msdb.dbo.sp_send_dbmail to embed the resultset directly into the body of the email:

    EXEC msdb.dbo.sp_send_dbmail

    @profile_name = 'SQL Server Agent Mail Profile'

    ,@recipients = @to_list

    ,@copy_recipients = @cc_list

    ,@body = @msg

    ,@query = 'SELECT source, emplid, fullName AS name,

    visaTypeFSA as fsaVisa, visaType as psVisa, reason

    FROM fsaAtlasReporting.dbo.tblDataLinkIDsReport'

    ,@subject = @subject

    ,@attach_query_result_as_file = 0

    ,@query_result_header = 1