|
The following
T-SQL system procedure samples demonstrate how to send query results (reports) to recepient(s):
EXEC msdb.dbo.sp_send_dbmail
@profile_name = 'SQLDBEmail',
@recipients = 'kevin.smith@AtlanticPacificDB.com',
@query = 'SELECT Color, Items=COUNT(*) FROM AdventureWorks2008.Production.Product
GROUP BY Color ORDER BY Items DESC',
@subject = 'Color usage in bike and related products',
@attach_query_result_as_file = 1 ;
SQL Server 2000:
EXECUTE master.dbo.xp_sendmail
'jane.smith@domain.com',
@query = 'select * from Orders where datediff(day, OrderDate,getdate())<30
order by RequiredDate ',
@no_header= 'FALSE',
@width = 72,
@dbuse = 'Northwind',
@subject= 'AutoNotice: Recent Orders',
@message='Orders for the last 30 days'
|