I have a string of email recipients in the format like this:
DECLARE @recipients VARCHAR(MAX); .... PRINT @recipients; /* the result person1@yahoo.com;person2@hotmail.com;person1@yahoo.com;... */
‘SELECT DISTIECT …’ is a simple and powerful SQL statement, but it works against a table. Is there a simple way to select distinct recipient from the recipient list variable like FOR loop in C# or Ruby?
FOR @recipient IN @recipients BEGIN -- send email to @recipient END
By the way, I am using TSQL in SQL server 2005.
Here’s a solution for you that uses a temporary table.
The idea is to continously parse the email from the string, insert it into a temporary table, and remove the parsed email from the remaining string.
You can use loop through the temporary table afterward to send your individual emails.