title: Select multiple SQL rows into one row
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/194852/concatenate-many-rows-into-a-single-text-string">Concatenate many rows into a single text string?</a>  </p>
  </blockquote>
  
  
  
  <p>Suppose I have table named <code>tblContractMail</code>.  Sample table with data given below:</p>
  
  <p><img src="https://i.stack.imgur.com/WUPnk.jpg" alt="enter image description here"> </p>
  
  <p>I need to write a SQL query that produces the following output:</p>
  
  <blockquote>
    <p>'abc@akij.net;efg@akij.net;hjk@akij.net'</p>
  </blockquote>
  
  <p>I know two possibilities:</p>
  
  <pre><code>DECLARE @str varchar(4000)
  SELECT @str = COALESCE(@str + ';', '') + strContract FROM tblContractMail 
  SELECT @str
  </code></pre>
  
  <p>and:</p>
  
  <pre><code>DECLARE @str varchar(4000)
  SET @str = (SELECT strContract + ';' FROM tblContractMail FOR XML PATH(''))
  SET @str = SUBSTRING(@str, 1, LEN(@str)-1)
  SELECT @str
  </code></pre>
  
  <p>Is there any way to get this output in a single query (I mean with out declaring any variables)?</p>