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
 General SQL Server Forums
 New to SQL Server Programming
 Not really a sql issue but !!!

Author  Topic 

lemondash
Posting Yak Master

159 Posts

Posted - 2007-05-30 : 07:05:13
I have a sql select script which runs at nine every morningnow at the moment it emails the results in a csv file format and this is running all under a dts job.

What i would like to do is run the sql script script and have the results in the body of the email instead of the csv file. It sonly because few of the big boys in the company can't open csv files on there blackberrys and it would be easier to view the results with in the email.

Any help would be great.

nr
SQLTeam MVY

12543 Posts

Posted - 2007-05-30 : 08:20:58
You can use xp_sendmail and put the results of a query in the body of the mail.

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

Jim77
Constraint Violating Yak Guru

440 Posts

Posted - 2007-05-30 : 09:15:52
Something like this I use to email to a blackberry and the format comes out quiet well :

EXEC xp_sendmail @recipients = 'Jim@Ler.co.uk ',
@query = ' SELECT Orphanisale ,
OrphanOsale
FROM prdatawarehouse.dbo.NoMatches ',
@copy_recipients = 'Matthew@Ler.co.uk ; SaraL@ler.co.uk ',
@subject = 'Unmatched Itemsales',
@message = '
There is orphaned stores in one of todays itemsales or offersales
files excluding store 1
***********************************************************************
The whole data import process will run again at 16:00 and these orphans will be
taken out if they still exist and will need to be imported manually :
***********************************************************************
The following information is available :


' ,

@separator = ' ',
@attach_results = 'false', @width = 80


if you create the stored procedure in the master database you only need to reference the database you are querying as per the red text and you can use xp_sendmail without prefixing it with master..xp_sendmail which I think is easier.
Go to Top of Page

lemondash
Posting Yak Master

159 Posts

Posted - 2007-05-30 : 09:43:41
I currently use this SP xp_smtp_sendmail would that do the same ?
Go to Top of Page

Jim77
Constraint Violating Yak Guru

440 Posts

Posted - 2007-05-31 : 07:16:11
you must be using sql 2005 , I am still using old school sql 2000 where xp_smtp_sendmail is not supported so I wouldnt know, sorry.
Go to Top of Page
   

- Advertisement -