I have a string of email recipients in the format like this:
DECLARE @recipients VARCHAR(MAX);
....
PRINT @recipients;
/* the result
[email protected];[email protected];[email protected];...
*/
"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.