I'm currently using a SQL+HTML script to send an email with the columns of my table mytable
. Right now, all the column titles are centered and each entry in the columns is aligned to the right using [th]
and [td]
respectively. I'm wondering how I can make the entries in the Vendor
column left-aligned while keeping everything else the same. Any help on this issue would be greatly appreciated.
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:left;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_Name</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">Analyst_Name</font></b></th></tr>';
--Select information for the Report--
Select @Body2= (select
Vendor_Name As [TD]
,OUTL_New_$ As [TD]
,OUTL_Old_$ As [TD]
,OUTL_Diff_$ As [TD]
,Analyst_Name As [TD]
from #mytable
For XML raw('tr'), Elements)
Set @Body = @TableHead2 + @Body2 + @TableTail
EXEC msdb.dbo.sp_send_dbmail
@recipients='<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="25444746654447460b464a48">[email protected]</a>',
@subject = My analysis',
@body = @Body,
@body_format = 'HTML';
end