January 12, 2010 at 9:49 am
Hi folks,
I have a client who want to use my data and he wants it in a weekly basis, the data could easily be generated using a single query. rather than create a big application to do this, I am wondering if it is possible to set up some SQL job to accomplish this?
Thank you.
January 12, 2010 at 10:28 am
You could create a data export in SSIS (or legacy DTS) that outputs .csv data to a file share. Then schedule that inside a job to run once a week.
January 12, 2010 at 10:31 am
You can also attach query results to a mail message with xp_sendmail.
January 12, 2010 at 10:33 am
Or you could set up Database Mail and send the data directly as a xls file using a stored proc called by a job.
January 12, 2010 at 10:44 am
Yeah, I know this can be done by SSIS, for lots of reason, I really don't like SSIS (compare to DTS)
January 12, 2010 at 10:45 am
lmu92 (1/12/2010)
Or you could set up Database Mail and send the data directly as a xls file using a stored proc called by a job.
Can you elaborate this? Thanks.
January 12, 2010 at 11:20 am
It depends on where you want to start...
Assuming, you need to start from the very beginning, I'd recommend the following article:
http://www.sqlservercentral.com/articles/Administration/introtodatabasemailinsql2005/2197/
Once you succesfully send the testmail you should check "sp_send_dbmail (Transact-SQL)" in BOL (Books Online).
January 12, 2010 at 11:40 am
lmu92 (1/12/2010)
It depends on where you want to start...Assuming, you need to start from the very beginning, I'd recommend the following article:
http://www.sqlservercentral.com/articles/Administration/introtodatabasemailinsql2005/2197/
Once you succesfully send the testmail you should check "sp_send_dbmail (Transact-SQL)" in BOL (Books Online).
Thanks, I have no problem sending email, but just wondering how to attach a query result as xls (or csv, text) format. Can you provide some sample code? Thanks lots.
January 12, 2010 at 11:50 am
Never mind, I know how to do it now. Thank you again for your help.
January 12, 2010 at 11:55 am
Based on BOL, extended by some more parameter (untested, but should work):
EXEC msdb.dbo.sp_send_dbmail
@profile_name = 'AdventureWorks Administrator',
@recipients = 'danw@Adventure-Works.com',
@query = 'SELECT COUNT(*) FROM AdventureWorks.Production.WorkOrder
WHERE DueDate > ''2004-04-30''
AND DATEDIFF(dd, ''2004-04-30'', DueDate) < 2' ,
@subject = 'Work Order Count',
@attach_query_result_as_file = 1 ,
@query_result_separator = '' ,--Tab
@query_attachment_filename = 'MyFile.xls'
January 12, 2010 at 11:00 pm
I tried this and its working fine.
Thanks for sharing.
But the result in the file is in improper manner.
Cheers,
- Win.
" Have a great day "
January 12, 2010 at 11:06 pm
Hi,
adding a new bit here, can we make this to work for GMail or Yahoo mails ?
any thoughts ?
as i tried in the past but never resolved.
Thanks in advance.
Cheers,
- Win.
" Have a great day "
January 13, 2010 at 12:27 am
You might want to check this thread.
Seemes like someone finally found a way to do it. I haven't tested it myself though...
Viewing 13 posts - 1 through 12 (of 12 total)
You must be logged in to reply to this topic. Login to reply