如何在sql中获取格式的数据?

时间:2019-07-18 21:47:42

标签: sql sql-server

我希望将SQL Server存储过程中表格式的数据以html形式发送。

我已经在SQL Server中尝试过此操作:

DECLARE @xml NVARCHAR(MAX)
DECLARE @body NVARCHAR(MAX)
DECLARE @SIGN VARCHAR(MAX)

SET @MailSubject = 'Scenario Wise Report as on - '+ CONVERT(VARCHAR(20), GETDATE() - 1, 103)

SET @body ='<html><head>
<table><tr>
<td valign="top"><table border="1" class="custom_class"><thead><tr><th colspan="9" bgcolor=yellow>Scenario Wise Report</th></tr></thead>
<tr><th>Scenario</th><th>Count</th></tr>
<tr>Email id not registered</tr>
<tr>119 Out of time frame</tr>
<tr>chargeback</tr>
<tr>90 out of time frame</tr>
<tr>direct credit</tr>
<tr>dispute form received</tr>
<tr>csa case</tr>
<tr>email received</tr>
<tr>reminder 1</tr>
<tr>reminder 2</tr>
<tr>reminder 3</tr>
<tr>exception</tr>
<tr>fallout</tr>

<tbody>'

SET @xml = CAST(( SELECT  email AS 'td','', out_of_time   AS 'td','' ,chargeback AS 'td','',out_of_time_90 AS 'td','',direct_credit AS 'td','',
dispute AS 'td','',csa AS 'td','',email_received AS 'td','',reminder_1 AS 'td','',reminder_2 AS 'td','',reminder_3 AS 'td','',
exception AS 'td','',fallout AS 'td'
FROM @count
FOR XML PATH('tr'), ELEMENTS ) AS NVARCHAR(MAX))
'</table></body></html>' 

SET @body = @body + @xml + '`

我想要这样的结果:-

Scenario                  Count

Email id not registered     60
119 Out of time frame      395
chargeback                 151
90 out of time frame         0
direct credit               43
dispute form received       18
csa case                    18
email received              15
reminder 1                 145
reminder 2                   0
reminder 3                   0
exception                   20
fallout                     45

Total                      910

但是我现在得到这个结果:

Scenario                 Count
Email id not registered    60
119 Out of time frame     395
chargeback                151
90 out of time frame        0
direct credit              43
dispute form received      18
csa case                   18
email received             15
reminder 1                145
reminder 2                  0
reminder 3                  0
exception                  20
fallout                    45
Total                     910

0 个答案:

没有答案