Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I've had similar issues when trying to use this approach to concatenation in the past. Often some messing around with the SELECT resolves it. The FOR XML approach to concatenation is more robust.</p> <p>I tried to reproduce the issue here though and couldn't (it worked correctly for me and output the 2 different email addresses in the concatenation).</p> <p>Does this work for you? If so maybe compare the execution plans and see what's different.</p> <pre><code>set nocount on create table #email_archive ( emailed_to CHAR(45) ) insert into #email_archive select 'deadlockIE12388nnhy32@hepmeplease.com;' union all select 'deadlockIE12388nnhy32@hepmeplease.com;' union all select 'deadlockIE12388nnhy32@hepmeplease.com;' union all select 'deadlockIE12388nnhy32@hepmeplease.com;' union all select 'deadlockIE12388nnhy32@hepmeplease.com;' union all select 'deadlockIE12388nnhy32@hepmeplease.com;' union all select 'deadlockIE12388nnhy32@hepmeplease.com;' union all select 'deadlockIE12388nnhy32@hepmeplease.com;' union all select 'deadlockIE1277yhygt@hepmeplease.com;' declare @errmsg varchar(max) = '', @subject nvarchar(255) = 'Run Away Email Monitor'; select @errmsg = REPLICATE(char(10),1)+ '# of Emails'+ REPLICATE(char(9),1)+ 'Email Address'+ REPLICATE(CHAR(10),1); select @errmsg = @errmsg +REPLICATE(char(9),1)+ CAST(COUNT(*) as CHAR(10))+ REPLICATE(char(9),1)+ CAST(MIN(emailed_to) as CHAR(45)) from #email_archive group by emailed_to order by COUNT(*) desc; print @errmsg; drop table #email_archive; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload