DATETIME SELECT SELECT INTO DATE PAD STRING DYNAMIC SQL CURSOR MONEY FORMAT PERCENT STORED PROCEDURE SQL SERVER AGENT JOB OPTIMIZATION WHILE LOOP OVER PARTITION BY UPDATE
 
 
SITE SEARCH SQLUSA.com VIDEOS
 
 
SQL E/BOOKS   WORLD, USA & SQL NEWS   FORMAT
SCRIPTS SQL 2005 SQL 2008 ARTICLES
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 = '[email protected]',

    @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
'[email protected]',
@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'

 


Exam Prep 70-461
SQL 2016 DESIGN & PROGRAMMING
 
 
 
DATETIME SELECT SELECT INTO DATE PAD STRING DYNAMIC SQL CURSOR MONEY FORMAT PERCENT STORED PROCEDURE SQL SERVER AGENT JOB OPTIMIZATION WHILE LOOP OVER PARTITION BY UPDATE