title: Using sp_send_dbmail to multiple recipients
body: <p>I have write the following in order to send  to each customers (from the query) an email. how can I solve it
  from the </p>
  
  <pre><code>SELECT Distinct (CUSTVENDAC) AS 'td','',
              Email AS 'td','',
              TTL_ITEMID AS 'td','',
              TTL_TRANSREFID AS 'td'
  FROM PARTS_RIN1 
  </code></pre>
  
  <p>I have 4 fields and I would like to send an e-mail to each <code>CUSTVENDAC</code> describing that he has the following <code>TTL_ITEMID</code> and <code>TTL_TRANSREFID</code>.</p>
  
  <pre><code>DECLARE @email VARCHAR(max)
  SET @email = ''
  
  SELECT @email = RTRIM(@email) + RTRIM(email) + ';'
  FROM PARTS_RIN1
  PRINT @email
  
  DECLARE @xml NVARCHAR(MAX)
  DECLARE @body NVARCHAR(MAX)
  
  SET @xml = CAST(( SELECT 
  Distinct (CUSTVENDAC) AS 'td','',
              Email AS 'td','',
              TTL_ITEMID AS 'td','',
              TTL_TRANSREFID AS 'td'
  FROM PARTS_RIN1             
  WHERE email= @email
  FOR XML PATH('tr'), ELEMENTS ) AS NVARCHAR(MAX))
  
  SET @body ='&lt;html&gt;&lt;body&gt;&lt;H2&gt;Order Info&lt;/H2&gt;
  &lt;table border = 2&gt; 
  &lt;tr&gt;
  &lt;th&gt; CUSTVENDAC &lt;/th&gt; &lt;th&gt; Email &lt;/th&gt; &lt;th&gt; TTL_ITEMID&lt;/th&gt;
  &lt;th&gt; TTL_TRANSREFID &lt;/th&gt; 
  &lt;/tr&gt;'    
  
  SET @body = @body + @xml +'&lt;/table&gt;&lt;/body&gt;&lt;/html&gt;'
  
  BEGIN
  
      EXEC msdb.dbo.sp_send_dbmail
        @profile_name = N'sp_send_dbmail', 
        @body = @body, 
        @body_format = 'HTML',
        @recipients = @email,
        @subject = 'Order Results'
  
  END
  </code></pre>