sp-send-dbmail

Using cursor in dbMail in sql server 2008

会有一股神秘感。 提交于 2019-12-29 10:03:33
问题 I am trying to send remittance info to our customers with check# and amount on the check. I am unable to send one email per customer with check num and amount and remittance info. Right now email gets generated but it is only picking one customer and sending emails equal to num of records which get pulled. Please have a look at my query below, probably I am messing up in the cursor part. New code Declare @body nvarchar(max) declare @docnum nvarchar(50) declare @numatcard nvarchar(50) declare

Using cursor in dbMail in sql server 2008

陌路散爱 提交于 2019-12-29 10:02:26
问题 I am trying to send remittance info to our customers with check# and amount on the check. I am unable to send one email per customer with check num and amount and remittance info. Right now email gets generated but it is only picking one customer and sending emails equal to num of records which get pulled. Please have a look at my query below, probably I am messing up in the cursor part. New code Declare @body nvarchar(max) declare @docnum nvarchar(50) declare @numatcard nvarchar(50) declare

How to send multiple emails from sql server database using sp_send_dbmail procedure

感情迁移 提交于 2019-12-24 11:40:25
问题 I have procedure which results a data table contains 3 columns Emails,proposal_Type,count(MatchestoEmail) the matches is based on proposal_type. Now I have to send a notification mails to the 'Emails' stating that they have these many number of matches based on Proposal_Type. the procedure output data will be like this. Emails Prop_Type Matches abc@gmail.com 1 3 abc@gmail.com 2 4 def@gmail.com 3 2 I want the mails to be recipient and the remaining two columns to in the Body of the Email with

sp_send_dbmail attachment encoding

一笑奈何 提交于 2019-12-21 20:32:45
问题 I am using sp_send_dbmail in SQL2005 to send an email with the results in an attachment. When the attachment is sent it is UCS-2 Encoded, I want it to be ANSI or UTF-8. Here is the SQL EXEC msdb.dbo.sp_send_dbmail @recipients = 'temp@example.com' , @query = 'DECLARE @string_to_trim varchar(60);SET @string_to_trim = ''1234''; select rtrim(@string_to_trim), ''tom''' , @query_result_header=0 , @subject = 'see attach' , @body= 'temp body' , @profile_name= N'wksql01tAdmin' , @body_format = 'HTML'

Attachment file \\SERVER\file.csv is invalid. [SQLSTATE 42000] (Error 22051). The step failed

柔情痞子 提交于 2019-12-20 04:59:19
问题 I've got 4 SQL servers: SQL Server 2005, SQL Server 2008, SQL Server 2008 R2 and SQL Server 2012. In SQL Server 2008 R2; I have created a SQL job that sends me email every Monday with reports from SQL Server 2005, SQL Server 2008 and SQL Server 2008 R2 on databases that are older than 3 months and it works just fine. But, now that I want to add SQL Server 2012, the job fails with the following error: Executed as user: NT AUTHORITY\SYSTEM. Configuration option 'show advanced options' changed

Stored procedure using sp_send_dbmail to send emails to multiple recipients queried from database

微笑、不失礼 提交于 2019-12-20 03:19:45
问题 Like the title says, I'm trying to make a stored procedure used to send emails to addresses stored in the database, often including multiple recipients. I've tried a few approaches to this, but I think I'm hitting a wall and would appreciate any input anyone has. The main issue I've had is querying the database for the addresses and passing that to sp_send_dbmail in a way that works. The address table is pretty simple, looks something like this, but much larger. Both columns are varchars:

How can I use sp_send_dbmail to send multiple queries?

若如初见. 提交于 2019-12-19 19:40:23
问题 I'm trying to send an email using sp_send_dbmail . I need it to send one query as an attachment and another as part of the body of the email. The problem is that sp_send_dbmail only has one @query parameter, and I can't see any way to add another one. Is there any way to either a) add a second query (with all of the parameters attached to it) or b) execute the query into a variable and then add that to the body of my email? I'm using sql-server 2005. TIA! 回答1: Use the @query parameter of the

How can I use sp_send_dbmail to send multiple queries?

旧城冷巷雨未停 提交于 2019-12-19 19:39:13
问题 I'm trying to send an email using sp_send_dbmail . I need it to send one query as an attachment and another as part of the body of the email. The problem is that sp_send_dbmail only has one @query parameter, and I can't see any way to add another one. Is there any way to either a) add a second query (with all of the parameters attached to it) or b) execute the query into a variable and then add that to the body of my email? I'm using sql-server 2005. TIA! 回答1: Use the @query parameter of the

Generic failure using sp_send_dbmail in SQL Server 2014

馋奶兔 提交于 2019-12-19 09:05:12
问题 I'm trying to use sp_send_dbmail to send the results of a query through a SQLAgent job in SQL Server 2014. I believe I have my DBMail profile set up properly but when running this: exec msdb.dbo.sp_send_dbmail @profile = 'TestProfile', @recipients = 'testmail@gmail.com', @subject = 'Test', @query = 'SELECT id FROM TestTable', @attach_query_result_as_file = 1, @query_attachment_filename = 'TestValues.txt' I get the following error message: Failed to initialize sqlcmd library with error number

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

感情迁移 提交于 2019-12-17 05:55:36
问题 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