sql - Can someone help me with Formatted HTML Table with TSQL -


i created sql server job query ( shown below) dynamical retrieve set of data, generates html table , email recipient. job work fine long query returns record set renders html tableas shown in attached image.on contrary, when query returns no record set, recipient gets blank email instead of table default values or null values. know how tweak code render html table default value of zeros whenever query returns no record set?

use dev;  declare @tablehtml  nvarchar(max);  set @tablehtml =n'<h3><font color="red">' +                  'the exams attempt   month of' + ' ' +                  datename(month, (dateadd(month,-1,dateadd(month, datediff(month, 0, ![alt text][1]getdate()), 0))) ) + '</h3>' +                 '<td>' + n'<table border="1">' +                     '<caption>' + '3rd attempt' + '</caption>'+                     n'<tr><th>app_lvl</th>' +                     n'<th>eligatt</th>' +                     n'<th>category</th>' +                     n'<th>result</th>' +                     n'<th>count</th>' +                     cast ( ( select td = sc_pracrslts.reg_lvl, '',td = sc_pracrslts.elig_attmpt_no, '',td = sc_pracrslts.category, '',td = sc_pracrslts.pass_ind, '',td = count(*), ''                 ars_copy..sc_pracrslts                 exam_dt >= '4/1/2015' , exam_dt < '5/1/2015'  ,                 sc_pracrslts.elig_attmpt_no = 3                 , sc_pracrslts.category = '1'                  group sc_pracrslts.reg_lvl,                            sc_pracrslts.category,                            sc_pracrslts.elig_attmpt_no,                            sc_pracrslts.pass_ind                   order sc_pracrslts.reg_lvl,                            sc_pracrslts.category,                            sc_pracrslts.elig_attmpt_no,                            sc_pracrslts.pass_ind                 xml path('tr'), type          ) nvarchar(max) )          + n'</table>' + '</td>' + '</tr>' +  '</table>';    exec msdb.dbo.sp_send_dbmail     @recipients=n'aboamah@abc.org',     @subject = 'exams attempt dashboard ',     @body = @tablehtml,     @body_format = 'html' ,     @profile_name='augie bomah' 

i tried isnull on each column , put value. like:

select  td = isnull(sc_pracrslts.reg_lvl, 'null') , '' ,         ![enter image description here][1] td = isnull(sc_pracrslts.elig_attmpt_no, 'null') , '' ,         td = isnull(sc_pracrslts.category, 'null') , '' ,         td = isnull(sc_pracrslts.pass_ind, 'null') , '' ,         td = count(*) , 

but didn't work !!


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -