我使用SQL + HTML脚本发送包含表mytable
的前5列的电子邮件。目前,我将所有列标题集中对齐,并且每个列条目都使用[th]
和[td]
重新对齐。如何使Vendor
列中的条目保持左对齐,同时保持其他所有内容相同?
DECLARE @dt datetime, @prev_dt datetime
SELECT @dt = dbo.GetDateOnly(getdate())
SELECT @prev_dt = dbo.GetDateOnly(getdate()-1)
SELECT top 5
Vendor,
OUTL_New_$,
OUTL_Old_$,
Outl_Diff_$ ,
OUTL_Diff_Perc,
Analyst
into #vpositive
FROM mytable
ORDER BY 4 DESC
--select * from #vpositive
if(@@ROWCOUNT>0)
begin
--drop table #email
DECLARE @Body2 varchar(max)
declare @TableHead2 varchar(max)
declare @TableTail varchar(max)
Set @TableTail = '</table></body></html>';
Set @TableHead2 = '<html><head>' +
'<hr style="height:1px;border:none;color:#333;background-color:#333;">'+
'<H5 style="color: #000000; font-family:Arial">2: VENDOR LEVEL TOP 5 OUTL $ <font color="blue">INCREMENTS -</font></H5>' +
'<style>' +
'td {border: solid black 1px;padding-left:5px;padding-right:5px;padding-top:1px;padding-bottom:1px;font-size:10pt;color:Black;text-align:right;font-family:Arial;} ' +
'th {border: solid black 1px;padding-left:5px;padding-right:5px;padding-top:1px;padding-bottom:1px;font-size:10pt;color:Black;text-align:center;font-family:Arial;} ' +
'</style>' +
'</head>' +
'<body><table cellpadding=0 cellspacing=0 border=0 width=auto>' +
'<tr bgcolor=#007336>'+
'<th><b><font color="white">Vendor</font></b></th>' +
'<th><b><font color="white">OUTL$ New</font></b></th>' +
'<th><b><font color="white">OUTL$ Old</font></b></th>' +
'<th><b><font color="white">OUTL$ Diff</font></b></th>' +
'<th><b><font color="white">OUTL$ Diff Perc</font></b></th>' +
'<th><b><font color="white">Analyst</font></b></th></tr>';
--Select information for the Report--
Select @Body2= (select
substring(Vendor,1,60) As [TD]
,'$ '+substring(parsename(convert(varchar,convert(money,cast(OUTL_New_$ as int)),1),2),1,13) As [TD]
,'$ '+substring(parsename(convert(varchar,convert(money,cast(OUTL_Old_$ as int)),1),2),1,13) As [TD]
,'$ '+substring(parsename(convert(varchar,convert(money,cast(OUTL_Diff_$ as int)),1),2),1,13) As [TD]
,substring(CAST(OUTL_Diff_Perc AS varchar(10)),1,4)+' %' As [TD]
,substring(Analyst,1,20) As [TD]
from #vpositive
For XML raw('tr'), Elements)
Set @Body = @TableHead2 + @Body2 + @TableTail
--Email
EXEC msdb.dbo.sp_send_dbmail
@recipients='abc@abc.com',
@subject = My analysis',
@body = @Body,
@body_format = 'HTML';
end
答案 0 :(得分:-1)
你试过这个:
<th align="left">
或者这个:
text-align: left;