Click here to Skip to main content
15,889,865 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
Hi.

I wonder if there is a remedy in sending out an email , if the record is blank. Then the email that is being sent is also blank. Seems like it does not complete the html code when a record is NULL


SQL
DECLARE @EmployeeName nvarchar(150), @htmlBody nvarchar(max)=N'',@htmlheader nvarchar(max),@htmlFooter nvarchar(max)

set @htmlheader = '<html><body>
<div style="padding:10px;width:677px">
<p style="font-size:14px; line-height:20px"><span style="color:red;font-weight:bold">Following item/s are added/updated:</span>
<br/> Employee Code: '+ cast(@EmployeeNo as nvarchar(10))+'<br/> Employee Name:' + @EmployeeName +'

					
<table style="font-size:9pt;border-collapse:collapse;width:100%" cellpadding="3px">
<tr>
<td style="width:100px;background:#CCCCCC;font-weight:bold;border:1px solid #888888">Item</td>
<td style="width:200px;background:#CCCCCC;font-weight:bold;border:1px solid #888888">Description</td>
<td  style="width:50px;background:#CCCCCC;font-weight:bold;border:1px solid #888888">Amount</td>
</tr>'

set @htmlFooter ='</div></body></html>'
	
SELECT @htmlBody=@htmlBody + '<tr>'
'<td style="border:1px solid #888888;">' +Item+'</td>'
'<td style="border:1px solid #888888;">' +ItemDesc+'</td>'
+'<td style="border:1px solid #888888;">' +Currency +' '+ CONVERT(nvarchar(20),cast(Amount as money),1) +'</td></tr>'
from (Select *,(CASE WHEN Status=2 then '(updated)' else ''  end) as StatuStr from EmpPPInsurance where EmployeeNo =@EmployeeNo and Status in (1,2)) T1 order by Item

				
Set @htmlBody = Replace(@htmlBody, '_x0022_', '''')
Set @htmlBody = Replace(@htmlBody, '_x0023_', '#')
Set @htmlBody = Replace(@htmlBody, '_x003D_', '=')
Set @htmlBody = Replace(@htmlBody, '_x003B_', ';')
Set @htmlBody = Replace(@htmlBody, '_x0020_', ' ')
			
SET @htmlBody=@htmlheader + @htmlBody + '</table>' + @htmlFooter 	


I would really appreciate if someone could help me on this.

Thanks
Posted
Updated 24-Nov-15 19:03pm
v2

1 solution

That depends on your code. Since you don't show any it's impossible to tell you what you're doing wrong.

Besides, why that hell would you send a blank email?
 
Share this answer
 
Comments
bjay tiamsic 25-Nov-15 1:07am    
Sorry I didnt know that i did not hit the update button. I've been editing it this morning.

Im not sending out a blank email, it just goes blank when a record is NULL.
Dave Kreskowiak 25-Nov-15 13:17pm    
OK, so check for the value of null before you go through creating the email for that record.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900