用于发送带有html表格式问题的电子邮件的存储过程

时间:2013-10-03 15:43:46

标签: html xml sql-server-2008 stored-procedures

以前的开发人员有一个在电子邮件中以html表格的形式发送电子邮件警报的过程,这是通过触发存储过程并传递相关参数来完成的。这有点超出了我的技能,但是我试图通过相同的程序发送电子邮件以便迟到。它工作正常格式和布局。查询是 -

SET @xml = CAST((   SELECT      td = '<td align = "Center">' + CONVERT(VARCHAR(12),EmployeeName) + '</td>'
                                , td = '<td align = "Center">' + CONVERT(VARCHAR(12),StartTime) + '</td>'
                                , td = '<td align = "Center">' + CONVERT(VARCHAR(12),Late) + '</td>'
                    FROM        #tempLateEmail  

                    FOR XML PATH('tr'),TYPE).value('.','NVARCHAR(MAX)'
                    ) AS NVARCHAR(MAX))

身体输出是:

SET @body = 
                  N'<style type="text/css">'
            + 'body {font-family: Arial;font-size:12px;} '
            + 'table{font-size:11px; border-collapse:collapse;table-layout: fixed} '
            + 'td{ border:1px solid black; padding:3px;} '
            + 'th{background-color:#F1F1F1;border:1px solid black; padding:3px;}'
            + 'h1{font-weight:bold; font-size:12pt}'
            + 'h2{font-weight:bold; font-size:10pt}'
        + '</style>'
        + '<body style="width:620px; margin:15px;">'
            + '<div style="margin:0 auto; width:300px">'
                + '<h1>Lateness Email on' + ' ' + convert(varchar, getdate(), 103) + '</h1>'
            + '</div>'
            + '<div style="float:left; width:250px">'
                + '<p>The following people appear to have been late today</p> '
            + '</div>'
            + '<div style="float:left; margin-left:20px; width:250px">'
                + '<div style="height:150px; overflow:auto">'
                + '<table width="250px">'
            + '<tr>'
            + '<th width = 100>Employee</th>'
            + '<th width =100>Expected Start Date</th>'
            + '<th width =100>Minutes Late</th>'
            + '</tr>'
                + @xml
                + '</table>'
                + '</div>'
            + '</div>'

            + '<div style="clear:both;"></div>'
        + '</body>' 

        SET @subject = 'Lateness Email for - ' + convert(varchar, getdate(), 103)

然后将它们并排输出而不是在表格中输出。我明白为什么要这样做,但我无法弄清楚该做些什么。希望我已经提供了足够的信息

1 个答案:

答案 0 :(得分:0)

根据Rohit Tiwari的评论,在代码顶部的末尾确实有<tr>缺失 -

SET @xml = CAST((   SELECT      td = '<td align = "Center">' + CONVERT(VARCHAR(12),EmployeeName) + '</td>'
                                , td = '<td align = "Center">' + CONVERT(VARCHAR(12),StartTime) + '</td>'
                                , td = '<td align = "Center">' + CONVERT(VARCHAR(12),Late) + '</td>**<tr>** '
                    FROM        #tempLateEmail  

                    FOR XML PATH('tr'),TYPE).value('.','NVARCHAR(MAX)'
                    ) AS NVARCHAR(MAX))

突出显示了上述更新。