SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Text file contents sent as email body via SQL?
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Rasta Pickles
Posting Yak Master

United Kingdom
171 Posts

Posted - 06/08/2013 :  10:23:32  Show Profile  Reply with Quote
Assume this scenario:

I have a simple two column text file, columns are "time" and "action". So the contents are something like

17:21:33 Database accessed
17:21:37 Query53 executed


I would like to send the contents of that text file as the email body (not as an attachment) via SQL Mail. What's the best way?

I can use BULK INSERT to pull the text file contents into a table and I am familiar with setting up the whole SQL Mail thing.

I am going to format the email as HTML so I don't simply want to do a

SELECT * FROM mytemptable


because the output doesn't look right (and in any case it all appears on one line for some reason).

Any pointers?

Thanks in advance.

visakh16
Very Important crosS Applying yaK Herder

India
52325 Posts

Posted - 06/08/2013 :  14:02:40  Show Profile  Reply with Quote
you can put results in table and use @query parameter of sp_send_dbmail to run query and sent results in mail. If you want to make it html then create a procedure to create html out of table data and then call the procedure as query inside

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

Rasta Pickles
Posting Yak Master

United Kingdom
171 Posts

Posted - 06/09/2013 :  01:45:55  Show Profile  Reply with Quote
Many thanks!
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52325 Posts

Posted - 06/09/2013 :  11:47:47  Show Profile  Reply with Quote
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.11 seconds. Powered By: Snitz Forums 2000