I have a complex select statement (the union of several queries) which outputs a single column e.g.
| email |
| test@domain.com |
| test2@domain.com |
| test3@domain.com |
I would like to feed this into the @blind_copy_recipients of sp_send_dbmail which requires a semi colon (;) separated list.
would normally use COALESCE and a variable to accomplish this but you can’t seem to do that with a statement with UNIONS.
Is there an easy way to do this?
Whilst typing this question is has occurred to me that a better way might be to use a cursor to cycle through the records and send the messages individually but I’m still interested in the answer…..
Avoid cursors as much as possible.
In the meantime, try this: