Saturday, 7 July 2012

sql to email send

------------first time only
--EXEC sp_configure 'show advanced options', 1;   
--GO   
--RECONFIGURE;   
--GO   
--EXEC sp_configure 'Ad Hoc Distributed Queries', 1;   
--GO   
--RECONFIGURE;   
--GO   
--EXEC sp_configure 'Web Assistant Procedures', 1;   
--GO   
--RECONFIGURE;   
--GO 

DECLARE @FinalQuery AS nVARCHAR(max)   
set @FinalQuery = 'select * from branch'

DECLARE @HEAD AS nVARCHAR(max)   
SET @HEAD ='Branch Report '' <br/> visahlasl'   
EXEC sp_makewebtask    
 @outputfile = 'd:\work_mandays.doc',    
 @query = @FinalQuery,    
 @colheaders =1,    
 @FixedFont=0,@lastupdated=0,   
 @resultstitle=@HEAD   
   
EXEC msdb.dbo.sp_send_dbmail       
@profile_name = 'zanvargroup',       
@recipients = 'VISHdsf@ddss.com',       
@body_format  ='HTML',       
@subject = 'Work Mandays BranchWise',       
@body  =  'Work Mandays BranchWise',       
@file_attachments ='d:\work_mandays.doc';