I have a SQL that write birthday emails in html format... it work fine, but if I want to fill fields with variables, it does not work.
for example ma p tag:
<p style="margin: 0; color: #f07d00; font-family: Open Sans, arial, sans-serif; font-size: 12px; font-weight: bold; text-transform: uppercase;">
@DISPONAME
</p>
So, in the email it displays @DISPONAME, that a variable which is set in top of the sql, befor the html is start. Now I want to active the @DISPONAME like '+ @DISPONAME +' and it does not work, the email will be created till this and the rest is blank and the @DISPONAME row is not shown too...
What is wrong? How do I insert it correct?
Thank you!
Erik
Edit: SQL Command before html starts...
While (select top 1 id from dbo.Geburtstag_aktiv where send_date is NULL) is not NULL Begin DECLARE @ID int, @DISPONENT nvarchar(100), @DISPONAME nvarchar(100), @EMAILMA nvarchar(100), @EMAILDISPO nvarchar(50), @copy nvarchar(50) DECLARE @MOBIL as nvarchar(100), @DURCHWAHL as nvarchar(100), @BRIEFANREDE as nvarchar(100), @MABRIEFANREDE as nvarchar(100) DECLARE @sub nvarchar(255), @tableHTML nvarchar(MAX), @HomeServerUrl nvarchar(100), @BEDIENERTEXT as nvarchar(100), @BEDIENERFAX as nvarchar(100), @BEDIENERBERUF as nvarchar(100) SET @ID = (select top 1 id from dbo.Geburtstag_aktiv where send_date is NULL) SET @DISPONENT = (select LTRIM(RTRIM(DISPONENT)) from dbo.Geburtstag_aktiv where ID = @ID) SET @DISPONAME = (select LTRIM(RTRIM(DISPONAME)) from dbo.Geburtstag_aktiv where ID = @ID) SET @EMAILMA = (select LTRIM(RTRIM(EMAILMA)) from dbo.Geburtstag_aktiv where ID = @ID) SET @EMAILDISPO = (select LTRIM(RTRIM(EMAILDISPO)) from dbo.Geburtstag_aktiv where ID = @ID) SET @BRIEFANREDE = (select LTRIM(RTRIM(BRIEFANREDE)) from dbo.Geburtstag_aktiv where ID = @ID) SET @copy = copy SET @MOBIL = (select LTRIM(RTRIM(MOBIL)) from dbo.Geburtstag_aktiv where ID = @ID) SET @DURCHWAHL = (select LTRIM(RTRIM(DURCHWAHL)) from dbo.Geburtstag_aktiv where ID = @ID) SET @sub = 'Herzlichen Glückwunsch zum Geburtstag!' SET @HomeServerUrl = (select single_value from [dbo].[tb_admin_single_value] where single_value_desc = 'HomeServerUrl') SET @BEDIENERTEXT = (select LTRIM(RTRIM(BEDIENERTEXT2)) from dbo.Geburtstag_aktiv where ID = @ID) SET @BEDIENERFAX = (select LTRIM(RTRIM(FAX)) from dbo.Geburtstag_aktiv where ID = @ID) SET @BEDIENERBERUF = (select LTRIM(RTRIM(DISPOBERUF)) from dbo.Geburtstag_aktiv where ID = @ID) SET @MABRIEFANREDE = (select LTRIM(RTRIM(BRIEFANREDE)) from dbo.Geburtstag_aktiv where ID = @ID)
edit: Code to send the email:
SET @tableHTML =
'<html>'
Html code
</html>';
EXEC msdb.dbo.sp_send_dbmail
@recipients = @EMAILMA,
@profile_name = 'SERVER2',
@subject = @sub,
@body = @tableHTML,
@body_format = 'HTML'
edit: here are some html code, which does not work with @variable
<tr>
<td>
<a href="callto:035100000@DURCHWAHL" style="margin: 0; color: #000; font-family: Open Sans, arial, sans-serif; font-size: 10px; text-decoration: none;">
Tel.: 0351 / 00000-@DURCHWAHL
</a>
</td>
</tr>