cjake2299
asked on
MS SQL SP Result NULL skews HTML formatting
Good morning experts!
I have a stored procedure that runs every night on my MS SQL 2005 Database. It takes and emails the results of the query in HTML Format, but if any part of the row is NULL then even the <TD></TD> are not created...which "skews" the whole table. It's not common, but at least one day a week a report will have at least one row that is "skewed".
I'm fine with the report sending an empty email if there was nothing done that day, but if a cell is NULL I still need the <TD></TD> elements. I tried adding ' ' to each column results...that failed because it can't add a blank space to (nothing).
Essentially, I need to ensure that every row contains the same number of columns regardless if a value is present or not. Any Thoughts?
I have a stored procedure that runs every night on my MS SQL 2005 Database. It takes and emails the results of the query in HTML Format, but if any part of the row is NULL then even the <TD></TD> are not created...which "skews" the whole table. It's not common, but at least one day a week a report will have at least one row that is "skewed".
I'm fine with the report sending an empty email if there was nothing done that day, but if a cell is NULL I still need the <TD></TD> elements. I tried adding ' ' to each column results...that failed because it can't add a blank space to (nothing).
SET @tableHTML =
N'<H1>SLX report for activities on ' + @Today + '</H1>' +
N'<table border="1">' +
N'<tr><th>Account</th><th>Contact Name</th><th>Opportunity Name</th>' +
N'<th>Description</th><th>Activity Type</th><th>Notes</th><th>Username</th>' + '</tr>' +
CAST ( ( SELECT td = ' ' + [ACCOUNTNAME], '',
td = ' ' + [CONTACTNAME], '',
td = ' ' + [OPPORTUNITYNAME], '',
td = ' ' + [DESCRIPTION], '',
td = ' ' + [CATEGORY], '',
td = ' ' + [NOTES], '',
td = ' ' + [USERNAME]
from sysdba.History
where CAST(CREATEDATE as Date) = convert(NVARCHAR,GetDate(), 112)
FOR XML PATH('tr'), TYPE
) AS NVARCHAR(MAX) ) +
N'</table>' ;
Essentially, I need to ensure that every row contains the same number of columns regardless if a value is present or not. Any Thoughts?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Better you ask us and fork over these virtual things called 'points', then ask your buddies what might be a stupid question.
Thanks for the split. Good luck with your project. -Jim
Thanks for the split. Good luck with your project. -Jim
ASKER