title: Multiple Emails From 1 Table
body: <p>I know how to generate an email with all the data from a table, but how can I generate multiple emails from one table all in one stored procedure?  Would I need to do multiple calls changing up the where clause of my select statement each time or is their a more efficient way of achieving such?  This is a table with garbage data but will get the point across of what I need to accomplish.  I need to send one email with in the body of the email the data for each individual city.  I know how to send the email and syntax for that, so that is not the issue.  Just how to send 1 email for each city</p>
  
  <pre><code>Create Table #Data
  (
    name varchar(100)
    ,zip int
    ,phone int
    ,city varchar(5)
  )
  Insert Into #Data Values
  ('A A', 1, 123, 'AAA'),
  ('B B', 12, 333, 'BBB'),
  ('C C', 32, 444, 'BBB'),
  ('D D', 66, 999, 'BBB'),
  ('E E', 99, 000, 'BBB'),
  ('F F', 323, 918, 'AAA'),
  ('G G', 568, 1412, 'AAA'),
  ('H H', 911, 1913, 'ERI'),
  ('I I', 010, 981212, 'EZS'),
  ('J J', 3, 812, 'FEC')
  
  DROP TABLE #Data
  </code></pre>
  
  <p>Obviously that produces a distinct city list of </p>
  
  <blockquote>
    <p>city<br>
    AAA<br>
    BBB<br>
    ERI<br>
    EZS<br>
    FEC<br></p>
  </blockquote>
  
  <p>How can I generate an individual email (all being sent to the same email address with the same from address) for each of the cities listed above?</p>
  
  <p>EDIT --
  @Greg if I am following you, would this syntax be something like you were explaining to me?</p>
  
  <pre><code>Declare @DistinctCityCount INT
  SET @DistinctCityCount = 5
  
  WHILE (@DistinctCityCount &lt;= 5)
  Begin
      --Here would generate an email for the 1st distinct city data
  End
  </code></pre>