SQL拼接 html 发送

--在Job BES_Daily_FTP_filedownload 中使用
ALTER proc [dbo].[RSP_FN_UNAPPLIED_Mail_Reminder]
as
Declare @MailAddr varchar(max)
DECLARE @xml NVARCHAR(MAX)
DECLARE @body NVARCHAR(MAX)    

--Generate receive person list
set @MailAddr = ‘‘
select @MailAddr=@MailAddr+s.User_Mail+‘;‘
from Mst_UserInfo s
where User_IsValid=1 and substring(User_IsMail,1,1)=‘8‘ and User_Mail is not null and User_Mail!=‘‘
order by s.User_Mail
--print @MailAddr    

--generate mail body
SET @xml =
CAST((
SELECT [Business_Unit] ‘td‘,‘‘
      ,isnull([Customer_Name],remitter_name) ‘td‘,‘‘
   ,[Receipt_No] ‘td‘,‘‘
      ,convert(varchar(10),[Receipt_Date],120) ‘td‘,‘‘
      ,convert(varchar(100),cast(Receipt_Unapplied_Amount as money),1) ‘td‘,‘‘ --Commas every three digits
      ,convert(varchar(100),cast(Receipt_Amount as money),1) ‘td‘,‘‘
      ,[Currency_Name] ‘td‘,‘‘
      ,Bank_Name ‘td‘ ,‘‘
      ,[Receipt_Remark] ‘td‘
--      ,[Bank_Account]
--      ,[Customer_JDE_No]
--      ,[Receipt_Year]
--      ,[Receipt_Period]
--      ,[Remitter_Bank_Name]
--      ,[Bank_Branch]
--      ,[Bank_Account]
--      ,[Bank_Charge_Amount]
--      ,[Receipt_Type]
--      ,[Receipt_GL_Date]
--      ,[Receipt_Applied_Amount]
--      ,[Receipt_Status]
--      ,[Receipt_Status_No]
--      ,[Batch_Name]
--      ,[Batch_Status]
--      ,[Customer_Oracle_no]
--      ,[Action_Date]
--      ,[Serial_No]
--      ,[Receipt_Remark]
--      ,[IsHistory]
--      ,[Download_Date]
  FROM [BankReceipt]
  left join mst_bankinfo on  [Remitter_Bank_Name] = bank_id
Where receipt_status_no in (100,300,1000) and business_unit in (‘pvg‘,‘pws‘,‘sgc‘)  and  Receipt_Status<>‘Unidentified‘
order by Receipt_No desc
FOR XML PATH(‘tr‘), ELEMENTS ) AS NVARCHAR(MAX))    

SET @body =‘<html><H1>Unapplied Receipt Report</H1>
<body><style type="text/css">
h1,body{font:10pt,"Arial"}
h1{font:small-caps 14pt}
table,td,th {border:1px solid #7F7F7F;border-collapse:collapse;}
table{width:100%}
th{background-color:#C0C0C0;font-weight:bold}
</style>
<table>
<tr>
<th>Entity</th>
<th>Remitter Name</th>
<th>Receipt No</th>
<th style="width:82px">Receive Date</th>
<th>Receipt Remain Amt</th>
<th>Receipt Total Amt</th>
<th>Currency</th>
<th>Remitter Bank Name</th>
<th>Receipt Remark</th>
</tr>‘
SET @body = @body + @xml +‘</table></body></html>‘    

--send mail
--EXEC msdb.dbo.sp_send_dbmail
--@blind_copy_recipients = @MailAddr,
--@body = @body,
--@body_format =‘HTML‘,
--@subject =‘Unapplied Receipt Report‘    

exec msdb.dbo.CL_SendSingleMail
‘‘--sendtousermailSysMail [[email protected]]
,‘‘--cc
,@MailAddr--@MailAddr--bcc
,‘SysMail‘--sendername
,‘[email protected]‘--senderaddr
,‘Unapplied Receipt Report‘--mailsubject
,@body--mailcontent
,‘normal‘  --importance low/normal/high   
时间: 2024-08-02 00:47:38

SQL拼接 html 发送的相关文章

4.mybatis动态SQL拼接/取值/OGNL

4.mybatis动态SQL拼接/取值 一.mybatis框架的SQL拼接是采用OGNL表达式进行的,以下我会列出常用的取值方法. 图片来源:慕课网 1.1常用的取值方法: 1.2特殊的取值方法: mod为取余数

SQL 拼接字符串(字符串中有变量) 转载的

http://blog.csdn.net/sikaiyuan2008/article/details/7848926 sql server数据库存储sql SQL SERVER拼接字符串(字符串中有变量)  总是忘记规律,转载过来以帮助记忆. 一.拼接字符串(整个字符串不分割)步骤: 首先在字符串的前后加单引号: 字符串中的变量以'''[email protected]+'''在字符串中表示: 若在执行时存在类型转换错误,则应用相应的类型转换函数,对变量进行类型转换(如cast()函数). 示例

多条件搜索问题 -sql拼接与参数化查询

来源:传智播客  免费开发视频. 问题:根据书名或出版社或作者查询书籍信息. using System; using System.Collections.Generic问题; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClie

SQL拼接小技巧(一)

# SQL拼接小技巧(一) # 2018/6/21 18:54:36 ---------- **关键字:  SQL , 1 = 1 ,1 = 2** ---------- 如下代码中SQL拼接使用了1=1和1=2防止请求参数中条件为空或SQL注入的方式猜测表名,字段名 public DomainPage<RealNameVerifyInfo> getVerifyList(String vin, String name, String phoneNum, String status, Strin

Mybatis的动态sql拼接语句

Mybatis的动态sql拼接语句 1.主配置文件SqlMapConfig.xml  <?xml version="1.0" encoding="utf-8" ?> <!DOCTYPE configuration         PUBLIC "-//mybatis.org//DTD Config 3.0//EN"         "http://mybatis.org/dtd/mybatis-3-config.dtd

PL/SQL 下邮件发送程序

对DBA而言,尽管在os级别下发送邮件是轻而易举的事情,然而很多时候我们也需要在PL/SQL中来发送邮件,比如监控job的执行状况等.本文根据网友(源作者未考证)的代码将其改装并封装到了package,感谢这位网友的无私奉献.文章首先给出演示调用该包发送邮件的情形后面给出了完整的代码.经测试Oracle 10g,Oracle 11g下均可用.关于os下发送邮件可参考:不可或缺的 sendEmail 1.调用SENDMAIL_PKG来发送邮件 [sql] view plain copy print

SQL 拼接多个字段的值&amp;一个字段多条记录的拼接

如student表: studentID studentName studentScore 01 Alice 90 02 Bill 95 03 Cindy 100 一.拼接多个字段的值 select studentID+‘-’+studentName+'-'+studentScore AS studentInfo from student 结果: 二.一个字段多条记录的拼接 select stuff((select '|'+studentName from student for xml pat

高性能安全式SQL拼接

不少开发人员在进行SQL拼接时头痛之极,不知道如何进行拼接操作才会更安全又不影响性能,下面我以存储过程为例与大家分享一个相对比较安全高效的方法 简介:存储过程(Stored Procedure)是在大型数据库系统中,一组为了完成特定功能的SQL 语句集,存储在数据库中,经过第一次编译后再次调用不需要再次编译,用户通过指定存储过程的名字并给出参数(如果该存储过程带有参数)来执行它.存储过程是数据库中的一个重要对象,任何一个设计良好的数据库应用程序都应该用到存储过程. 格式: CREATE PROC

多条件分页查找(SQL拼接方法)

def startTime=params.startTime+" 00:00:00"  def endTime=params.endTime + " 23:59:59"  def SQL ="from Timage where 1=1 "  params.max = 2 //设置偏移量  if (!params.offset) params.offset = 0  //  params.offset=""  if(params