1

我创建了一个 sp_send_dbmail,它从我的数据库中获取查询信息,但现在当它返回日期时,需要空格的地方会显示一个“T”。

我试图用空格替换“T”Set @Body = Replace(@Body, '<TRRow>T</TRRow>', '') 但没有任何反应

请帮忙 !

Set @TableHead = '<html><head>' +
              '<H1 style="color: #000000">SpeedDail Lookup</H1>' +
              '<style>' +
              'td {border: solid black 1px;padding-left:5px;padding-right:5px;padding-top:1px;padding-bottom:1px;font-size:11pt;color:Black;} ' +
              '</style>' +
              '</head>' +
              '<body><table cellpadding=0 cellspacing=0 border=0>' +
              '<tr bgcolor=#F6AC5D>'+
              '<td align=center><b>Erf ID</b></td>' +
              '<td align=center><b>SpeedDail Base</b></td>' +
              '<td align=center><b>Contact No</b></td>' +
              '<td align=center><b>Indicator</b></td>' +   
              '<td align=center><b>Gate ID</b></td>' +
              '<td align=center><b>Is Deleted</b></td>' +
              '<td align=center><b>Insert Date</b></td>' +  
              '<td align=center><b>Update Date</b></td>' +                 
              '<td align=center><b>Person ID</b></td></tr>';

--Select information for the Report--   
Select @Body= (Select 
   ErfId           As [TD],
   SpeedDialBase   As [TD],
   ContactNo       As [TD],
   Indicator       As [TD],
   GateId          As [TD],
   IsDeleted       As [TD],
   InsertDate      As [TD],
   UpdateDate      As [TD],
   PersonId        As [TD]
FROM [DB].[dbo].[SpeedDialLookup]

For XML raw('tr'), Elements)

-- Replace the entity codes and row numbers
Set @Body = Replace(@Body, '_x0020_', space(1))
Set @Body = Replace(@Body, '_x003D_', '=')
Set @Body = Replace(@Body, '<tr><TRRow>1</TRRow>', '<tr bgcolor=#C6CFFF>')
Set @Body = Replace(@Body, '<TRRow>0</TRRow>', '')


Set @Body = @TableHead + @Body + @TableTail

输出

2012-05-02T10:30:05.153
4

1 回答 1

2

在查询中明确格式化您的日期。

Select @Body= (Select 
   ErfId           As [TD],
   SpeedDialBase   As [TD],
   ContactNo       As [TD],
   Indicator       As [TD],
   GateId          As [TD],
   IsDeleted       As [TD],
   convert(nvarchar, InsertDate, 121)      As [TD],
   convert(nvarchar, UpdateDate, 121)      As [TD],
   PersonId        As [TD]
FROM [DB].[dbo].[SpeedDialLookup]
For XML raw('tr'), Elements)
于 2013-03-22T07:08:36.730 回答