码迷,mamicode.com
首页 > 数据库 > 详细

SQL Server 2008 自动发邮件HTML表格

时间:2018-09-26 11:43:18      阅读:342      评论:0      收藏:0      [点我收藏+]

标签:ima   nvarchar   esc   ati   sel   产品   mail   htm   cell   

DECLARE @emailBody NVARCHAR(MAX);
SET @emailBody = N‘<style>table{table-layout:fixed;width:1200px;border:1px solid #000000;border-collapse:collapse;font-size:12px;empty-cells:show;}‘

  • N‘th,td{border:1px solid #000000;padding:3px;}</style>‘
  • N‘<H2>销退单</H2>‘ --标题
  • N‘<table>‘ + N‘<thead><tr>‘
  • N‘<th style="width:80px;">品号</th>‘
  • N‘<th style="width:90px;">品名</th>‘
  • N‘<th style="width:350px;">规格</th>‘
  • N‘<th style="width:150px;">产品序列号</th>‘
  • N‘<th style="width:80px;">数量</th>‘
  • N‘<th style="width:80px;">退货原因</th>‘
  • N‘</tr></thead><tbody>‘ --表头
  • CAST(( SELECT c.ITEM_CODE AS td ,
    ‘‘ ,
    b.ITEM_DESCRIPTION AS td ,
    ‘‘ ,
    b.ITEM_SPECIFICATION AS td ,
    ‘‘ ,
    b.UDF021 AS td ,
    ‘‘ ,
    ‘<div style="text-align:right;">‘
    • CAST(CAST(b.PRICE_QTY AS DECIMAL(20,
      4)) AS VARCHAR(20))
    • ‘</div>‘ AS td ,
      ‘‘ ,
      b.REMARK AS td ,
      ‘‘
      from SALES_RETURN a
      left join SALES_RETURN_D b ON a.SALES_RETURN_ID = b.SALES_RETURN_ID
      left join ITEM c ON b.ITEM_ID = c.ITEM_BUSINESS_ID
      where DOC_NO = ‘2700-201809250001‘
      FOR
      XML PATH(‘tr‘) ,
      TYPE
      ) AS NVARCHAR(MAX))
  • N‘</tbody></table>‘;

    SELECT @emailBody = REPLACE(REPLACE(@emailBody,
    ‘<‘, ‘<‘),
    ‘>‘, ‘>‘);
    select @emailBody

select c.ITEM_CODE,b.ITEM_DESCRIPTION,b.ITEM_SPECIFICATION,b.UDF021,b.PRICE_QTY, b.REMARK from SALES_RETURN a
left join SALES_RETURN_D b ON a.SALES_RETURN_ID = b.SALES_RETURN_ID
left join ITEM c ON b.ITEM_ID = c.ITEM_BUSINESS_ID
where DOC_NO = ‘2700-201809250001‘

SQL Server 2008 自动发邮件HTML表格

标签:ima   nvarchar   esc   ati   sel   产品   mail   htm   cell   

原文地址:http://blog.51cto.com/13885809/2285780

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!