SQL电子邮件表格格式给出科学值而不是固定小数

时间:2015-10-09 16:34:54

标签: sql-server sql-server-2008 html-email database-mail

我有一个查询,以表格格式将结果发送到我的电子邮件。我使用此链接作为参考。 https://www.mssqltips.com/sqlservertip/2347/send-email-in-a-tabular-format-using-sql-server-database-mail/

我能够成功发送包含我想要的数据的电子邮件,但价值不是我想要的方式。

enter image description here

当我使用HTML运行查询时,我得到了正确的格式化值。

enter image description here

在实现html表格格式时,我需要在脚本中做些什么来获取固定值而不是科学记数法?任何帮助都非常感谢。

DROP TABLE #timetot 

DECLARE @intVar INT 

SET @intVar=0; 

; 
WITH ss 
     AS (SELECT a.rowid, 
                a.employee, 
                Sum(b.value) AS Total 
         FROM   employeetimesheets b 
                RIGHT JOIN employees a 
                        ON a.rowid = b.empid 
         WHERE  b.day >= Dateadd("d", -6, '2015-10-10') 
                AND b.day <= Dateadd("d", -0, '2015-10-10') 
         GROUP  BY a.rowid, 
                   a.employee 
         UNION ALL 
         SELECT rowid, 
                employee, 
                @intVar AS Total 
         FROM   employees 
         EXCEPT 
         SELECT empid, 
                employee, 
                @intVar AS Total 
         FROM   employeetimesheets a 
                INNER JOIN employees b 
                        ON a.empid = b.rowid 
         WHERE  a.day >= Dateadd("d", -6, '2015-10-10') 
                AND a.day <= Dateadd("d", -0, '2015-10-10')) 
SELECT * 
INTO   #timetot 
FROM   ss 

DECLARE @xml NVARCHAR(max) 
DECLARE @body NVARCHAR(max) 

SET @xml = Cast((SELECT [rowid]    AS 'td', 
                        '', 
                        [employee] AS 'td', 
                        '', 
                        [total]    AS 'td', 
                        '' 
                 FROM   #timetot 
                 ORDER  BY rowid 
                 FOR xml path('tr'), elements) AS NVARCHAR(max)) 
SET @body ='<html><body><H3>Employees with Un-finished or Null Timesheets</H3> <table border = 1>  <tr> <th> RowId </th> <th> Employee </th> <th> Total </th> </tr>' 
SET @body = @body + @xml + '</table></body></html>' 

EXEC msdb.dbo.Sp_send_dbmail 
  @profile_name = '***', 
  @body = @body, 
  @body_format ='HTML', 
  @recipients = '****.com', 
  @subject = 'E-mail in Tabular Format'; 

0 个答案:

没有答案