<p>I'm pulling email address records from a table in SQL Server 2005, and want to build a single string to use as the <code>@recipients</code> list with <code>sp_send_dbmail</code>. The table has a field called EmailAddress and there are 10 records in the table.</p>

<p>I'm doing this:</p>

<pre><code>DECLARE @email VARCHAR(MAX)
SELECT
    @email = ISNULL(@email + '; ', '') + EmailAddress
FROM
    accounts
</code></pre>

<p>Now @email has a semi-delimited list of 10 email address from the accounts table.</p>

<p>My questions is why/how does this work? Why doesn't @email only have the last email address in the table?</p>

Because for each row you concatentate the current value of
```
@email
```
with the next result in
```
EmailAddress
```
.  String concatenation is just like calling a function, in that it must evaluate the result for each row in sequence.