Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

how do I send to more than 1 dynamic mails?

$
0
0

Hi,

I want to be able to send mails to specific mails.

For example that works perfectly sending to only one mail:

DECLARE @recipients VARCHAR(4000)

SELECT 
   @recipients = [user] + '@skyvision.net'
                        from Vehicle_Users
where [user] in ('ThomasY')

USE msdb
EXEC sp_send_dbmail
      @profile_name = 'MailProfile',
      @recipients = @recipients,
      @subject = 'Vehicles ready for Kilometraje treatment',
      @body = 'The Following Vehicles ready for Kilometraje treatment:'

In this example the mail was sent to ThomasY@skyvision.net.

But lets say I want to sent to 2 mails or more, what do I do?

I think I need to make a loop with ';' on the @recipients variable, separating between the mails somehow... But I'm not sure how...

Any ideas?


Viewing all articles
Browse latest Browse all 23857

Trending Articles