I need to set up a job in SQL Server 2008 to run at the first of the month sending an email to our customers. However, I do not know how to loop through the results of the s
The error is here where you have many rows trying to be assigned to a single variable
SET @Recipients =(SELECT DISTINCT a.EMail
FROM a
--approximately 600 email addresses
You'd need to change it to a separated list thus
SET @Recipients = STUFF(
(select DISTINCT ';' + CAST(a.EMail AS varchar(max))
FROM a FOR XML PATH ('')
)
,1,1, '')
Note: @Recipients will need to be varchar(max)
the problem is @recipients = @MailRecipients
. It is expecting a string (an email address) and you are giving it a recordSet.