troubleshooting Question

How do I show blank cells in html formatted email sent from sql database mail?

Avatar of Kevin Smith
Kevin SmithFlag for United States of America asked on
Microsoft SQL ServerMicrosoft SQL Server 2005Microsoft SQL Server 2008
4 Comments1 Solution1241 ViewsLast Modified:
I have the following stored procedure that sends an html email, but if there's no data in one field it throws the next column into the first empty column.  How do I correct that?
SET @tableHTML =
    N'<h1>Upcoming QA Dates</h1>'
  + N'<table border="1">'
  + N'<tr><th>Job Number</th>'
  + N'<th>FU Date</th>'
  + N'<th>PM Name</th></tr>'
  + CAST ( (  SELECT
                  td = p.JobNumber    , ''
                , td = wo.FUDate2_60   ,  ''
                , td = pm.PMName   ,  ''
              FROM (projmgmtsrv.dbo.tbl_QA AS wo
              LEFT JOIN projmgmtsrv.dbo.tbl_Jobs AS p
              ON wo.ProjectID = p.ProjectID)
              LEFT JOIN projmgmtsrv.dbo.tbl_PM AS pm ON p.PM = pm.PMID              
              FOR XML PATH('tr'), TYPE
           ) AS NVARCHAR(MAX)
  + N'</table>';
EXEC msdb.dbo.sp_send_dbmail
@profile_name ='mssjobbook'
, @recipients=''
, @subject = 'Message Subject'
, @body = @tableHTML
, @body_format = 'HTML';
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 4 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros