SQLUSA.com
SQL SERVER 2008 GRAND SLAM
FREE TRIAL  CLICK HERE TO ORDER  SEARCH
SQL JOBS SQL Server Training Scripts JOB BANK
  SQL Server 2008 Training Scripts  
  SQL Server 2005 Training Scripts  
News SQL Server Articles SQL Format

How to email reports using xp_sendmail?

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'

 


Order SQL 2008 GRAND SLAM Today!
SQLUSA.com Home Page
SQL Server Training at www.sqlusa.com.
SQL Server 2008 Video Training at www.sqlusa.com.
SQL Server 2005 Training Videos at www.sqlusa.com.
Microsoft SQL Server 2000 Training Videos at www.sqlusa.com.

FREE SQL & Business Intelligence / OLAP Short Videos on YOUTUBE.com

Microsoft Community Contributor 2011
Invest in Your SUCCESS!

Search SQLUSA FREE SQL Server Articles & FREE T-SQL Scripts


Copyright 2005-2011, SMI Corp. All Rights Reserved.

SQL Server 2012 is a program product of Microsoft Corporation.
SQL Server 2008 is a program product of Microsoft Corporation.
SQL Server 2005 is a program product of Microsoft Corporation.
SQL Server 2000 is a program product of Microsoft Corporation.