html - 如何在 SQL+HTML 脚本生成的电子邮件中左对齐列条目

标签 html css sql-server

我正在使用 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

最佳答案

你试过吗:

<th align="left">

或者这个:

text-align: left;

关于html - 如何在 SQL+HTML 脚本生成的电子邮件中左对齐列条目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34912299/

相关文章:

html - 如何使子div的高度高于父div?

css - 网站在移动设备上没有响应,但对调整大小有响应

sql-server - Node js knex 和 mssql 错误 - 'TypeError: _this.driver.Connection is not a constructor'

sql-server - Sql Server 2008 - 排序规则类型之间的差异

sql - 数据库规范化——谁是对的?

jquery - 让图像留在原处

javascript - 有没有办法在 Reactjs 中设置元素的初始高度?

jquery - Kendo UI - 并排显示图表

html - 两个子 div,一个相对父 div 的位置,另一个相对浏览器?

html - 网站移动 View 右侧的白色空白