I would like to send an email for each row of the result set using sp_send_dbmail.
What is a suitable way to accomplish this without using loops?
Edit: I do not insist that the loop is not suitable here, but is there a set-based way. I tried to create a function, but the function cannot call the stored procedure inside it. Just another func or extended sp (which I wouldn't do either).
The best way to achieve this is to put the email sending logic in a user-defined function.
SELECT MyEmailFunc (emailaddress) FROM MyTable
, , , . :
UDPATE MyTable SET SENT = MyEmailFunc ( ) = 0
- , ( ).
, , .
, .
.
( , ) , .
"" , , , , - -, .
(, ), , .
- , , , "" . .
, :
"SendMails" Insert
sp_send_dbmail
:
Truncate Table SendMails insert into SendMails (From, To, Subject,text) Select field1,field2,field3,field4 from MyTable
, . .
WHILE SQL, " "
BTW: ,
, , SQL Server: -D
SSRS - TSQL .
Source: https://habr.com/ru/post/1708767/More articles:What is the preferred process for installing applications on OSX? - installerExpand or reduce the screen size depending on the screen size - htmlАвтоматическое обновление фаз сборки Xcode для цели? - build-processIs creating an association entry unobtrusive when trying to access? - ruby | fooobar.comASP.NET application and local timezone - timezoneIn Visual Studio, can I disable my application signing when debugging? - .netRun sgml-pretty-print when opening xml file in emacs? - emacsМогу ли я захватить предупреждение "Unrecognized escape" при компиляции регулярного выражения? - regexGoogle Maps tiles - how to divide 30 thousand coordinates into tiles - mapsJam when solving the minimum pairing problem - algorithmAll Articles