我正在尝试将电子邮件单独发送到收件人列表。我收到错误:
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@example.com" could not be bound.
这是我的代码的简化版本,假设 table1 是一个有效的现有表,并且 name 和 email 是现有列。
declare @current_mailaddress varchar(50), @query varchar(1000)
set @current_mailaddress = 'email@example.com'
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
所以根据错误,格式(大概是@query)是错误的。我想不通。有任何想法吗?