Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 SQL Server Administration (2005)
 XP_Sendmail Help

Author  Topic 

CSK
Constraint Violating Yak Guru

489 Posts

Posted - 2008-06-19 : 15:02:12
Hello,

I want to send a reslut as a xls file. so I did it throug BCP. The same time i need to send file in mail. Here i am stucked. Could any one please advise me to solve this problem?

Declare @date varchar(100), @SqlBcp Varchar(1000)
Select @date = Convert( varchar, getdate(),112)+Replace (Convert(varchar, Getdate(),114),':','')
Set @SqlBcp = 'Master..Xp_CmdShell '+'''bcp "Select * from KK_TEST..JobStatus" queryout "C:\testing'+@date+'.xls" -c -T'''

EXEC master.dbo.xp_sendmail
@recipients = N'xxxx@xxxxxxxxx.com',
@query = N'Exec ('+ @SqlBcp +')',
@subject = N'Failed Job Details',
@message = N'The contents of JobStatus ',
@attach_results = 'TRUE',
@width = 250 ;


Thanks
Krishna

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-06-19 : 15:28:03
Use @attachments not @attach_results. Do not run your EXEC @SqlBcp inside xp_sendmail, execute it before the call.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

CSK
Constraint Violating Yak Guru

489 Posts

Posted - 2008-06-19 : 15:32:50
Thanks Tara.
Go to Top of Page
   

- Advertisement -