SQL MAIL 输出表格疑问
抱歉我只有20分了
我想用SQL邮件输出一张表格,格式大致如下:
-----------------------------------------------
|名称 | @name | 电话 | @phone|
-----------------------------------------------
|地址 | @add | 联系人| @contract|
------------------------------------------------
然后我写了代码如下:
declare @prob nvarchar(max),@name nvarchar(max),@phone nvarchar(max),@add nvarchar(max),@contract nvarchar(max)
set
set @prob=
'<table border=1>'+CAST((select top 1
'<tr><td>名称:</td><td>'+@name+'</td><td>电话</td><td>'+@phone+'</td></tr>'
'<tr><td>地址:</td><td>'+@add+'</td><td>联系人</td><td>'+@contract+'</td></tr>'
from tc_account
FOR XML PATH('tr'), TYPE ) as nvarchar(max))
+ N'</table>'
--set @mail=@mail
EXEC msdb.dbo.sp_send_dbmail
@profile_name = '邮件配置文件名',
@recipients = '邮件地址',
@body = @prob,
@subject = @name
<style>
.tt th{background:#a9a9a9;background-color:red;color:white;}
.tt tr{font-weight:100;font-size:12;width:120pt;text-align:center;font-family:Lucida Sans Unicode;}
.tt tr.altrow{
background-color:#c7e5ff;
}
.tt td{width:100px;padding:5px;word-wrap: break-word; word-break : break-all;}
</style>'
<table class = "tt" border="1" style="border-collapse:collapse;table-layout:fixed;word-break:break-all;">