I am trying to send emails individually to a list of recipients. I am receiving the error:
Msg 22050, Level 16, State 1, Line 0
Error formatting query, probably invalid parameters
Msg 14661, Level 16, State 1, Procedure sp_send_dbmail, Line 478
Query execution failed: Msg 4104, Level 16, State 1, Server xxxxxx, Line 1
The multi-part identifier "[email protected]" could not be bound.
Here is a simplified version of my code, asssuming table1 is a valid existing table and name and email are existing columns.
declare @current_mailaddress varchar(50), @query varchar(1000)
set @current_mailaddress = '[email protected]'
set @query = 'select distinct name, email from table1
where email = ' + @current_email
exec msdb.dbo.sp_send_dbmail
@recipients = @current_email,
@subject = 'test',
@query = @query
So according to the error, the formatting (of presumably the @query) is wrong. I can't figure it out. Any ideas?