Schedule And E-mail Query Results In HTML Formated Email
Aug 14, 2004
Could anyone walk me through how to do the following:
Schedule a query to run at a designated time
Embed the resulting table in a HTML email
Email the HTML formated results someone automatically
Can this be done with SQL Server only or is there a third party app?
I know its alot but I'm having a hard time finding resourses.
View 1 Replies
ADVERTISEMENT
Feb 4, 2002
I need to create a "simple" sql query but have it formatted and then emailed
to individuals. I am trying to convert over from Oracle but I am having a
hard time getting the query to be formatted the way I want. Here is the select statement I tried to use with no luck with xp_sendmail:
SELECT ALARM ID, TIMESTAMP as TIME, CLASS, RESOURCE, P, L, F, ALARM_MESSAGE
FROM ALARM_LOG WHERE ([TIMESTAMP] < GETDATE() - 1) ORDER BY [TIMESTAMP];
Here what the output should look like with the column headers underlined and
then the column data (notice the column heading ALARM MESSAGE is on the
next line before any data):
ALARM ID TIME CLASS RESOURCE P L F
-------------------- ----------- ----- ---------------- - - -
ALARM_MESSAGE
-------------------------------------------------------------
B3_TEMP_ALM 02-02@11:21 ALARM BUILDING3_TEMP N G G
BUILDING 3 TEMPERATURE ALARM, CALL SECURITY.
B5_TEMP_ALM 02-02@11:22 ALARM BUILDING5_TEMP N G G
BUILDING 5 TEMPERATURE ALARM, CALL SECURITY.
How can I run the query and have it formatted and emailed out?
What is the best way to accomplish this?
Thank you,
Mark
View 1 Replies
View Related
Aug 11, 2005
Hi,I need to limit results in the following query type:http://www.somewhere.com/php/sql-a....ql_order=&pos=1I found a reference that says I should be able to use LIMIT x[,y], butI don't know where/exactly how to add that to the string. Once I knowwhat it's supposed to look like, and can write something to generateit.If someone could post an example using the above and limiting theoutput to 100 records starting at position 1, that would be great.
View 1 Replies
View Related
Sep 12, 2002
i have to create a scheduled task that does the following:
a) creates an Excel Spreadsheet from a SQL Query
b) sends the spreadsheet to a user
i then need to schedule this task so that it runs every day and creates a NEW spreadsheet (doesnt matter it the name is the same as long as it overwrite what is already there)
HELP me PLEASE i dont like this SQL Game anymore !!
Daniel.:mad: :confused:
View 5 Replies
View Related
Aug 18, 2015
I have to send mail with HTML format and attaching multiple files dynamically via send mail task.
View 10 Replies
View Related
Apr 17, 2007
Hello,
I want to email the results of the query. The query output can be email either as the HTML body of the email to be sent or as a excel attachement.
I am wondering as to what would be the best way to achive this.
a) I could have a email client module in C# or VB.NET 2.0, which would fetch the query resultset and store it in a dataset. I format it as HTML body and send the email using System.NET. For excel, can use XSLT
Please suggest if there is any other approach that would be more suitable.
Thanks.
View 3 Replies
View Related
Aug 14, 2007
I'm very new to SQL but I have figured out how to do my first query. Now I would like to automate it to send the query as an attachment to users automatically (scheduler/cron??). How would you go about this, I need step by step hints. I'm using SQL Query Analyzer ver 8.00.2039 to generate the query from CDR records. Is this even possible?
Thank you for any guidance.
View 3 Replies
View Related
Sep 27, 2007
is it possible to use send mail task to send results of a query via email? if it can be sent then what would the result look like? will it be like excel type format or fixed length? or comma delimited?
and obviously -- how can I accomlish it?
thanks
View 5 Replies
View Related
Jul 20, 2005
Hi,I'm not sure if this is possible as i've googled everywhere, but i have aselect query that returns a customer record with their associated salesorders. I would like to automate a process which sends an email reminder toeach customer in the database, that has outstanding orders. This emailreminder should have the results of the query regarding their account.The table structure are as follows.---------------------Customer_tbl---------------------CustomerIDAccountNoNameEmailAddress---------------------Order_tbl---------------------OrderIDCustomerIDReferenceAmountDateOutstanding_flgCan anyone help?Sen.
View 2 Replies
View Related
Aug 8, 2015
I’m running a data integrity procedure from an agent job that is a scheduled weekly maintenance task which emails the results of my query, and is working properly.
I would however like this to only receive the email it the query contains results, and not send it no records are found to prompt me to take action.
Â
My code less the personal information
 Â
EXEC msdb.dbo.sp_send_dbmail   Â
@profile_name
= '',
     @recipients
= '',
      @subject
= 'Database Integrity - Import Errors',
[Code] ....
View 5 Replies
View Related
Sep 3, 2007
Hi,
Does anyone have an example of how to send the results of a query using sql mail? I m using sql server 2000 and have never used sql mail before.
Hope someone can help
Thanks
View 1 Replies
View Related
Jun 21, 2006
I have several tasks that I don't want to use conditional failure on. I have a ON ERROR send mail task right now that works. I want to have that send mail task include query results from a separate query. How do I do that?
Peter Cwik
View 8 Replies
View Related
Jan 2, 2014
Is there a way to export query results to an excel fie and add that file as an attachment in the email? All this has to be done using SQL query and it needs to be automated. My coworker tried using Openrowset and BCP, but it is not working.
View 3 Replies
View Related
Nov 26, 2014
possible to send Pivot query results as automated database email ?
View 3 Replies
View Related
Nov 16, 2005
It seems that using the Send Mail Task, there is no option for me to format my email as HTML. I have all my HTML code in a string and need to format my email to send the string as an HTML email. What would be the best way to approach this?
View 6 Replies
View Related
Jun 20, 2001
I have a proc that generates report content, then emails it, to some sales people. I'd like to use HTML to format the report content (bold letters, underlined, tab spaces, etc), but all I see in the resulting email, is the HTML tags with the content. I've tried to find a way to set the "content type" to text/html (like you'd do in VBScript) but that setting is nowhere to be found in xp_sendmail.
Any ideas on how to make this work, or perhaps another way to format the email content from within a stored proc?
View 1 Replies
View Related
Sep 27, 2001
I want to create an application using CDO for mass mailing, in which I have schedule an email for all contacts. How do I schedule a job from my asp page?
I dont want to depend on administrator every time for scheduling job. It will automatically schedule from asp page when user creat an email newsletter.
How do I this? Any suggestion will be welcomed.
Ashish
View 1 Replies
View Related
Jul 10, 2007
I need to convert a record set to HTML and send it as e-mail. Is it possible to do this in SSIS?
View 1 Replies
View Related
Apr 27, 2015
I wanted to implement the feature to send the email in HTML format from SQL. Which option will be more easy and less resource consumption? Like
sp_send_dbmail or sp_OAMethod or anything else?
View 2 Replies
View Related
Apr 4, 2008
Hi, I need help please.
I want to send an HTML Email
I have an Htm file that i want to use as my email body on Send Mail Task
MessageSourceType: File Connection
MessageSource: Email.htm
It sends the email with the file in the body but not in HTML format
it outputs the HTML tags + data
eg: <span style="font-size:9.0pt;">Period: 2008.04</span>
I used the same file in a DTS package & that works fine.
Please Assist!
Regards
View 2 Replies
View Related
Jun 5, 2008
Hi all!
I have a proc which send email as a text. But now I have to rewrite her to send email as html and embed a picture there.
I use DatabaseMail with sp_send_dbmail.
Does anybody know how to sort out it?
If somebody another way to send email as html with picture don't hesitate, say me.
Thanks in advance!
View 10 Replies
View Related
Jan 28, 2014
I have dumped html in a table and am looking to extract email addresses from it. Within the html, the email addresses are followed and preceded by blank spaces. I am playing around with the following code:
SELECT RIGHT(@email, LEN(@email) - CHARINDEX('@', @email)) as Domain
but have been unable to extract whole email addresses.
View 4 Replies
View Related
Nov 5, 2015
I have a table that gets queued up with a list of people for example email, first name, temporary login account and temporary password.How would i create a store procedure to feed these fields into the html message for each record. For example:
Dear <first name>,
Your temporary access is listed below.
Login: <temporary login>
Password: <temporary password>
I am not sure how you insert the data into the html message. It has to be in html because the message has a couple hyperlinks.
View 6 Replies
View Related
Aug 28, 2006
We have a DTS package that sends smtp email from an ActiveX script task. The body of the emails are in template files that we read in and then replace values relating to the customer.
I am looking for suggestions of handling this process from an SSIS package. This is what our existing code does.
'**********************************************************************
' Visual Basic ActiveX Script
'************************************************************************
Function Main()
'********************************************************************************************
' Email results
'********************************************************************************************
Dim oRS, objMessage, fTemplate
Set fso = CreateObject("Scripting.FileSystemObject")
Set oRS =DTSGlobalVariables("ToBeNotified").Value
oRS.MoveFirst
Do While NOT oRS.EOF
Set objMessage = CreateObject("CDO.Message")
Set objMessage2 = CreateObject("CDO.Message")
objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objMessage2.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
'Name or IP of Remote SMTP Server
objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = DTSGlobalVariables("RemoteSMTPServer").Value
objMessage2.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = DTSGlobalVariables("RemoteSMTPServer").Value
'Server port (typically 25)
objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objMessage2.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
'Type of authentication, NONE, Basic (Base64 encoded), NTLM
objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
objMessage2.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
'Your UserID on the SMTP server
objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") = "CustomerService"
objMessage2.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") = "CustomerService"
'Your password on the SMTP server
objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "cslogin"
objMessage2.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "cspassword"
objMessage.Configuration.Fields.Update
objMessage2.Configuration.Fields.Update
objMessage.Sender = DTSGlobalVariables("EmailFrom").Value
objMessage2.Sender = DTSGlobalVariables("EmailFrom").Value
objMessage.From = DTSGlobalVariables("EmailFrom").Value
objMessage2.From = DTSGlobalVariables("EmailFrom").Value
objMessage.To = oRS.Fields("ContactEmail").value
' objMessage.To = "me@ourmail.com"
objMessage2.To = DTSGlobalVariables("EmailBCC").Value
' objMessage2.To = "me@ourmail.com"
If oRS.Fields("Rejected").value = 1 Then
'Rejection Message
objMessage.Subject = "electronic request notification"
If oRS.Fields("ProductType").value = "Fixed" Then
Set htmlTextStream = fso.OpenTextFile (DTSGlobalVariables("EmailTemplateRejectedFixed").Value)
Else
Set htmlTextStream = fso.OpenTextFile (DTSGlobalVariables("EmailTemplateRejectedVariable").Value)
End If
Else
'Successful results
objMessage.Subject = "electronic confirmation #" + CSTR(oRS.Fields("ConfirmationId").value)
objMessage2.Subject = "Customer request for hard copy of contract"
'Add Terms and Conditons document
termDocument = DTSGlobalVariables("TermDocumentsRepository").Value + CSTR(oRS.Fields("TermDocument").Value) + ".pdf"
If fso.FileExists(termDocument) Then
objMessage.AddAttachment termDocument
objMessage2.AddAttachment termDocument
End If
If oRS.Fields("ProductType").value = "Fixed" Then
Set htmlTextStream = fso.OpenTextFile (DTSGlobalVariables("EmailTemplateSuccessFixed").Value)
Else
Set htmlTextStream = fso.OpenTextFile (DTSGlobalVariables("EmailTemplateSuccessVariable").Value)
End If
End If
htmlText = htmlTextStream.ReadAll
htmlText = Replace( htmlText , "[OurLogo]" , DTSGlobalVariables("EmailLogo").Value)
htmlText = Replace( htmlText , "[CustomerName]" , oRS.Fields("ContactFirstName").value + " " + oRS.Fields("ContactLastName").value)
If oRS.Fields("Rejected").value = 0 Then
htmlText = Replace( htmlText , "[ConfirmNumber]" , oRS.Fields("ConfirmationId").value)
htmlText = Replace( htmlText , "[OrderDate]" , oRS.Fields("SalesDate").value)
htmlText = Replace( htmlText , "[ProductName]" , oRS.Fields("ProductType").value)
htmlText = Replace( htmlText , "[Months]" , oRS.Fields("TermMonths").value)
htmlText = Replace( htmlText , "[Price]" , oRS.Fields("SalesPrice").value)
htmlText = Replace( htmlText , "[Units]" , oRS.Fields("SalesPriceUnit").value)
htmlText = Replace( htmlText , "[StartDate]" , oRS.Fields("FlowStartDate").value)
htmlText = Replace( htmlText , "[AccountNumber]" , oRS.Fields("AccountNumber").value)
End If
objMessage.HTMLBody = htmlText
objMessage2.HTMLBody = htmlText
objMessage.Send
If oRS.Fields("SendHardCopy").value = True AND oRS.Fields("Rejected").value = 0 Then
' Attach Instructions for Hard Copy delivery
instructionDocument = DTSGlobalVariables("TermDocumentsRepository").Value + "Instructions.txt"
set file = fso.CreateTextFile(instructionDocument, true)
file.WriteLine("The customer has requested a hard copy of their contract to be sent to them.")
file.WriteLine("")
file.WriteLine("Instructions:")
file.WriteLine("1) Print the email")
file.WriteLine("2) Print the attached Terms & Conditions document")
file.WriteLine("3) Mail both items to the address below")
file.WriteLine("")
file.WriteLine("Customer Address:")
file.WriteLine(oRS.Fields("ContactFirstName").value + " " + oRS.Fields("ContactLastName").value)
file.WriteLine(oRS.Fields("BillingAddress1").value)
If oRS.Fields("BillingAddress2").value <> "" Then
file.WriteLine(oRS.Fields("BillingAddress2").value)
End If
file.WriteLine(oRS.Fields("BillingCity").value + ", " + oRS.Fields("BillingState").value + " " +oRS.Fields("BillingZip").value)
file.Close
set file=nothing
objMessage2.AddAttachment instructionDocument
fso.DeleteFile(instructionDocument)
objMessage2.Send
End If
set objMessage = nothing
set objMessage2 = nothing
oRS.MoveNext
Loop
Main = DTSTaskExecResult_Success
End Function
All suggestions are appreciated.
SK
View 1 Replies
View Related
Jul 3, 2001
Using the stored proc XP_Sendmail i am able to send mails successfully. But i need to format the mail.. so for formatting i am using HTML tags.. so when i am sending the mail the html tags are getting displayed as it is. So pls can any body tell me how i can send the HTML formatted mail.
View 2 Replies
View Related
Nov 23, 2000
Hi to all,
I use sqlmail to send mails to clients, but I must send a report mail in HTML format...
is possible ????
this is my code, that return a simple string and not a HTML page when I open the mail:
------------------------------------------------------------------------
------------------------------------------------------------------------
set nocount on
declare @message varchar(8000)
declare @tempmsg varchar(8000)
declare @attach varchar(255)
declare @msg_id varchar(255)
declare @subject varchar(255)
declare @status int,
@originator varchar(255),
@cc_list varchar(255),
@date varchar(255),
@originator_address varchar(255)
Set @message='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">'
Set @message=@message + '<!-- -->'
Set @message=@message + '<HTML>'
Set @message=@message + '<HEAD>'
Set @message=@message + '<TITLE>Novità di Microsoft Italia - Anno 2 Numero # 20</TITLE>'
Set @message=@message + '<META content="text/html; charset=iso-8859-1" http-equiv=Content-Type>'
Set @message=@message + '<META content="MSHTML 5.00.2920.0" name=GENERATOR>'
Set @message=@message + '</HEAD>'
Set @message=@message + '<BODY>'
Set @message=@message + '<TABLE bgColor=#ffffff border=0 cellPadding=8 cellSpacing=0 width=600>'
Set @message=@message + '<TD vAlign=top width=220>'
Set @message=@message + '<FONT face=Verdana,Arial,Helvetica size=2 style="FONT-FAMILY: Verdana; FONT-SIZE: 11px">'
Set @message=@message + '<IMG alt="Software
gratuito" border=0 height=50 src="http://www.microsoft.com/italy/newsletter/images/sw.gif" width=180>'
Set @message=@message + '<TABLE border=0 cellPadding=0 cellSpacing=0>'
Set @message=@message + ' <TD>'
Set @message=@message + '<FONT face=Verdana,Arial,Helvetica size=2 style="FONT-FAMILY: Verdana; FONT-SIZE: 11px">'
Set @message=@message + '<A href="http://www.microsoft.it/italy/adv/jump.asp?cod=0020_wordup"> Word 2000 - Aggiornamento: protezione della stampa unione </A>'
Set @message=@message + '</FONT>'
Set @message=@message + '</TD>'
Set @message=@message + '</TABLE>'
Set @message=@message + '</BODY>'
Set @message=@message + '</HTML>'
EXEC master.dbo.xp_sendmail @recipients = 'emiliano.cecchetti@tei.ericsson.se',
@subject = 'Report',
@message = @message
---------------------------------------------------------------------------------
Thanks for any help,
Emiliano.
View 4 Replies
View Related
Oct 24, 2007
hi there,
the subject line says it all. is there a way to send nicely formatted html email from within a stored procedure that returns a dataset?
thanks!
chris
View 2 Replies
View Related
Dec 26, 2006
I'm new to SQL Express. I wonder if SQL Express has the functionality to create a store procedure which can retrieve data from tables and send the result to someone by email.
Also, if it has the functionality, could this activity be scheduled running on certain time?
If not, what's the best way to do this.
Any suggestion is appreciated.
Thanks
View 2 Replies
View Related
Mar 9, 2005
I am using SQL Mail to send an email. Is there some way to send it with an HTML body?
View 1 Replies
View Related
Dec 2, 2014
I have a job below, which takes the results and send to the users in email.But I have a question, how can I send only one email with all rows, not to send the for every row on table separated email.
DECLARE @Body VARCHAR(MAX)
DECLARE @StartDate DATETIME
DECLARE @EndDate DATETIME
DECLARE @RowCountINT
DECLARE@idINT
declare@departmentnvarchar(30)
[code]....
View 2 Replies
View Related
Jan 22, 2004
Wonder if anyone can help me out here.
I'm trying to set up a job to run overnight that mails me the size of all the databases on SQL Server.
The way I'm getting the size of the db's is by running the following in SQL Query Analyzer...
EXEC sp_MSforeachdb @command1="print '?' select cast(name as varchar(32)), round(size * 8 / 1.024,3) from ?..sysfiles"
Can anyone suggest a way that I can export the results of this to a text file that can then be mailed to me as part of a scheduled job.
Or can anyone suggest a better/easier way of doing this??
Thanks in advance. :)
View 6 Replies
View Related
Mar 28, 2008
while i was trying to execute the code for Sending an "HTML Mail Message with the Script Task" given at the link below http://msdn2.microsoft.com/en-us/library/ms403365.aspx
following error was encountered.
DTS Script Task has encountered an exception in user code:
Project namecriptTask_098956444e9f4ae195c3565569c9444b
The element cannot be found in a collection. This error happens when you try to retrieve an element from a collection on a container during execution of the package and the element is not there
at Microsoft.SqlServer.Dts.Runtime.Variables.get_Item(Object index)
at ScriptTask_098956444e9f4ae195c3565569c9444b.ScriptMain.Main() in dts://Scripts/ScriptTask_098956444e9f4ae195c3565569c9444b/ScriptMain:line 29
please help me
View 7 Replies
View Related
Sep 30, 2015
I am using the below code to send HTML Email body to multiple recipients and CC, its working fine. Now i have to attach multiple files in that mail. Is there any possibilities to attach multiple files with the below code else provide any other code to achieve this task.
Code:
/*
  Microsoft SQL Server Integration Services Script Task
  Write scripts using Microsoft Visual C# 2008.
  The ScriptMain is the entry point class of the script.
[code]...
View 6 Replies
View Related