sp-send-dbmail

Convert a SQL query result table to an HTML table for email

不打扰是莪最后的温柔 提交于 2019-12-17 05:53:12
问题 I am running a SQL query that returns a table of results. I want to send the table in an email using dbo.sp_send_dbMail. Is there a straightforward way within SQL to turn a table into an HTML table? Currently, I'm manually constructing it using COALESCE and putting the results into a varchar that I use as the emailBody. Is there a better way to do this? 回答1: Here is one way to do it from an article titled "Format query output into an HTML table - the easy way". You would need to substitute

Convert a SQL query result table to an HTML table for email

旧巷老猫 提交于 2019-12-17 05:53:07
问题 I am running a SQL query that returns a table of results. I want to send the table in an email using dbo.sp_send_dbMail. Is there a straightforward way within SQL to turn a table into an HTML table? Currently, I'm manually constructing it using COALESCE and putting the results into a varchar that I use as the emailBody. Is there a better way to do this? 回答1: Here is one way to do it from an article titled "Format query output into an HTML table - the easy way". You would need to substitute

Send dbMail from SQL Server 2000 with Tabular structured data?

房东的猫 提交于 2019-12-11 11:29:22
问题 I am trying to achieve this kind of formatted data from my select statement and have it send via database mail in SQL SERVER 2000. I know how to do this in SQL 2008. Column1 | Column 2 ------------------ Value 1 | Value 2 Value 1 | Value 2 Value 1 | Value 2 回答1: I have realized that this can not be done. To achieve this I created .bat file and stored procedures and sendmail utility. First call this in your .bat file osql -S %ServerName% -d %dbname% -U %username% -P %password% -Q "EXEC " -o

sp_send_dbmail keep sending email

蓝咒 提交于 2019-12-11 09:17:26
问题 I created a SP which rebuild/reorganize my indexes. If an error occurs, the sp_send_dbmail notifies me the error. The call is something like this EXEC MSDB.DBO.sp_send_dbmail @profile_name=@profile_name, @recipients = 'email@domain.com', @body=@Message, @body_format='TEXT', @Subject=@Subject; The last week, worked fine, I received the errors by email. But last night, when an error occured, sent a email, and now is sending the same email continuously. On the job activity monitor the job is

Send email from SQL server for each row of a dataset

让人想犯罪 __ 提交于 2019-12-11 08:22:15
问题 I have built a stored procedure for sending an email reminder to a set of employees each week. The SQL server agent runs a scheduled procedure each week that builds this weeks dataset of employees and then I need to have each of the employees receive an email but I cannot use the email stored proc inline with the scheduled SELECT statement. This would be possible using a function but I am using EXEC msdb.dbo.sp_send_dbmail to send mail which cannot be executed in a function. 回答1: Use a stored

SQL Email to CSV, Results have Line Splitting issues

99封情书 提交于 2019-12-11 07:25:01
问题 This question is similar to several questions I've found where Line Feeds or carriage returns cause copying SQL grid results to Excel to have Line Splitting issues and your results will be cut off and started on the next row. Name Order# Date PartDescription Store Phone# ---- ------- ------ ---------------- ----- ----------- Tom's 3181 10/7/2017 SB4356 Artwork... Downtown 208.452.6354 Will instead look like this Name Order# Date PartDescription Store Phone# ---- ------- ------ ---------------

Can't CATCH Errors from sp_send_dbmail

空扰寡人 提交于 2019-12-11 06:34:01
问题 We use sp_send_dbmail to notify us of certain problems and sometimes we attach files to the emails. Occasionally we will get an Error 32 (file in use) error. I've put some code together to send the email without the attachment in this situation but no matter what I do I'm unable to CATCH the error and ignore it. I'd like to be able to handle or ignore any errors from sp_send_dbmail because this causes a job failure in production. I tried implementing the technique described in this article

meaning of the values of sent_status on msdb.dbo.sysmail_mailitems

心已入冬 提交于 2019-12-09 12:56:06
问题 I am sending emails from SQL Server, and need to map the values of the sent_status column on the msdb.dbo.sysmail_mailitems table to something more descriptive. So far I have identified two values: 1 = 'Sent' 2 = 'Failed' Are there any more possible values, and if so what do they represent? 回答1: sent_status, --0 new, not sent, 1 sent, 2 failure or 3 retry. 回答2: On the MSDN page for the related msdb.dbo.sysmail_allitems table, the description for sent_status says: The status of the mail.

Stored procedure using SP_SEND_DBMAIL sending duplicate emails to all recipients

爱⌒轻易说出口 提交于 2019-12-08 15:58:44
问题 I have a stored procedure that is run every night which is supposed to send the results of a query to several recipients. However on most days it ends up sending a duplicate email a minute later. The code I am using is as follows (all emails and database refs have been changed): EXEC msdb.dbo.sp_send_dbmail @recipients = 'email1@email.com', @copy_recipients = 'email2@email.com;email3@email.com;email4@email.com', @subject = 'Example Email', @profile_name = 'ExampleProfile', @query = 'SELECT

SQL Server SP_SEND_DBMAIL Image file attachment

十年热恋 提交于 2019-12-06 02:47:30
问题 I am using a trigger on a table to send an email using sp_send_dbmail. I want to include a file attachment in the email of an image type. The raw data for the jpeg is stored in the ndl_Image column which is of type binary. I have the following code:- DECLARE @ReferenceID varchar(max) DECLARE @Recipient varchar(Max) DECLARE @Body varchar(max) DECLARE @Subject varchar(max) DECLARE @Q varchar(max) --Get the EntryId and FormID for the inserted data. SET @ReferenceID = 40 SET @Recipient = (SELECT