我有一个表格,其中填充了oldUserID,newUserID,名称和电子邮件。我想将sp_send_dbmail用于每一行的电子邮件。例如:
oldUserID | newUserID | 名称| 电子邮件 21213125 | 2355233571 | 汤姆| tom@gmail.com 65465465 | 4564884664 | 垫子| mat@gmail.com
oldUserID | newUserID | 名称| 电子邮件
21213125 | 2355233571 | 汤姆| tom@gmail.com
65465465 | 4564884664 | 垫子| mat@gmail.com
依此类推,持续200行。有什么方法可以将sp_send_dbmail发送到每行的电子邮件,包括oldUserID和newUserID?邮件中的输出将类似于:
“您的旧用户ID:21213125,您的新用户ID:2355233571”
我希望不要手动输入每个emailadress。
谢谢!
DECLARE @txt NVARCHAR(MAX) , @name NVARCHAR(60) , @email VARCHAR(100) DECLARE cur CURSOR FAST_FORWARD READ_ONLY LOCAL FOR SELECT 'Your old user id: ' + CAST(oldUserID AS NVARCHAR(100)) + ', your new user id: ' + CAST(newUserID AS NVARCHAR(100)), name, email FROM ... OPEN cur FETCH NEXT FROM cur INTO @txt, @name, @email WHILE @@fetch_status = 0 BEGIN EXEC msdb.dbo.sp_send_dbmail @profile_name = ... , @recipients = @email , @subject = @name , @body = @txt , @body_format = 'HTML' FETCH NEXT FROM cur INTO @txt, @name, @email END CLOSE cur DEALLOCATE cur