sp_send_dbmail - 多行作为正文

时间:2017-04-27 16:16:52

标签: sql-server

我有一个类似于以下设置的表:   PERSONID |姓氏|将First_Name | feeDescription | feebalance | client1_email | client2_email

1|Test|Joe|2017 Fees|90.00|joe@test.com|joe2@test.com
1|Test|Joe|2017 Parking|40.00|joe@test.com|joe2@test.com
2|Sample|Nellie|2018 Membership|120.00|whoanellie@test.com|Null

我想要做的是创建一个每周运行一次的SQL作业,并通过电子邮件向用户发送余额。我想要包含一个已发送邮件列,以便他们只收到一次电子邮件,但如果添加了新费用,则会收到新邮件。如果不为null,它将发送到client1_email,如果不为null,则发送到client2_email。

身体看起来类似于:

Dear Joe Test:
You have the following outstanding account fees with us:
     2017 Fees          $90.00
     2017 Parking       $40.00

然后继续处理表格的其余部分:

 Dear Nellie Sample:
 You have the following outstanding account fees with us:
     2018 Membership   $120.00

某些personID可能有1个费用,有些10个。有没有办法实现这个目标?

2 个答案:

答案 0 :(得分:0)

如果你想简单地在你的身体中嵌入一个CTRL + LF(回车),那么只需使用ascii代码。

CHAR(13)+CHAR(10)

Here is a similar question

答案 1 :(得分:0)

试试吧

SELECT 'Dear ' + Last_Name + ' ' + First_Name + '
You have the following outstanding account fees with us:
' + feeDescription +'   ' + feebalance
from table
相关问题