dboyd02
asked on
db mail need to send select in HTML format
I am getting the folling errors on this snip of code:
Msg 8114, Level 16, State 5, Line 178
Error converting data type varchar to float.
The select code in @ACEEmail returns the results I need, but I am trying to have format contol over the email, rather than dumping the records into the email body.
Please help,
thanks
Msg 8114, Level 16, State 5, Line 178
Error converting data type varchar to float.
The select code in @ACEEmail returns the results I need, but I am trying to have format contol over the email, rather than dumping the records into the email body.
Please help,
thanks
Declare @ACEEmail as float (1500)
Declare @ACEEmailBody varchar (1500)
begin
set @ACEEmail ='select dbo.Users_Master.namereg , dbo.secureToken.usedBy34, dbo.secureToken.serialNBR from dbo.Users_Master Left Join dbo.secureToken on dbo.secureToken.usedBy34 = dbo.Users_Master.user34 Where dbo.secureToken.[Enabled] = ''No'' '
--set @sql = 'select dbo.Users_Master.NameReg,(select top 1 dbo.secureToken.[DateDeath] from dbo.secureToken where usedBy34 = ''' + replace(@user, '''', '''''') + ''') as expiresDate from dbo.Users_Master where dbo.Users_Master.user34 = ''' + replace(@user, '''', '''''') + ''' '
set @ACEEmailBody = '<html><table border = 0> The following users have tokens that are expiring: Please activate the token listed below.<br> <br>' + str(@ACEEmail,8,0) + '</strong><br><br> Thanks, <br><br> Karla</table></body></html>'
EXEC msdb.dbo.sp_send_dbmail
@recipients = 'darryl.emily@scresearch.net',
@body = @ACEEmailBody,
@body_format ='HTML',
@subject ='Replacement Tokens',
@query = @ACEEmailBody,
@from_address = 'Karla.workman@scresearch.net',
@execute_query_database= AssetManagement
End
"@ACEEmail" has to be declared either nvarchar(max) or varchar(max)
Declare @ACEEmail as nvarchar(max) -- (if you use it for exec @ACEEmail)
or
Declare @ACEEmail as varchar(max)
Declare @ACEEmail as nvarchar(max) -- (if you use it for exec @ACEEmail)
or
Declare @ACEEmail as varchar(max)
ASKER
I get the same error:
Msg 8114, Level 16, State 5, Line 178
Error converting data type varchar to float.
if I change DECLARE @ACEEmail varchar (max)
or
DECLARE @ACEEmail nvarchar (max)
Msg 8114, Level 16, State 5, Line 178
Error converting data type varchar to float.
if I change DECLARE @ACEEmail varchar (max)
or
DECLARE @ACEEmail nvarchar (max)
ASKER
Is there a way to put the @ACEEmail select into the html formated @body???
@ACEEmail datatype should be float as you are doing string operation "str(@ACEEmail,8,0)".
and also assign the float value to @ACEEmail variable not the string value
and also assign the float value to @ACEEmail variable not the string value
ASKER
I changed to this and get the same error:
Msg 8114, Level 16, State 5, Line 174
Error converting data type varchar to float.
I might be confused as to how to assign the float.
Msg 8114, Level 16, State 5, Line 174
Error converting data type varchar to float.
I might be confused as to how to assign the float.
DECLARE @ACEEmail float
DECLARE @ACEEmailBody varchar (max)
BEGIN
SET @ACEEmail ='select dbo.Users_Master.namereg , dbo.secureToken.usedBy34, dbo.secureToken.serialNBR FROM dbo.Users_Master Left Join dbo.secureToken on dbo.secureToken.usedBy34 = dbo.Users_Master.user34 Where dbo.secureToken.[Enabled] = ''No'' '
SET @ACEEmailBody = '<html><table border = 0> The following users have tokens that are expiring: Please activate the token listed below.<br> <br>' + str(@ACEEmail,8,0) + '</strong><br><br> Thanks, <br><br> Karla</table></body></html>'
EXEC msdb.dbo.sp_sEND_dbmail
@recipients = 'darryl.emily@scresearch.net',
@body = @ACEEmailBody,
@body_format ='HTML',
@subject ='Replacement Tokens',
@query = @ACEEmail,
@FROM_address = 'Karla.workman@scresearch.net',
@execute_query_database= AsSETManagement,
@query_result_separator=' ',
@attach_query_result_as_file = 'TRUE',
@query_result_width=200
END
--END Email module
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Msg 8114, Level 16, State 5, Line 178
Error converting data type varchar to float.
Open in new window