title: Column is invalid in select list
body: <p>I am trying to add a <code>Nvarchar</code> column to my select list which I need in the result set. But when I execute I get this error:</p>
  
  <blockquote>
    <p>Column 'dbo.SourceEntity.SourceName' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.</p>
  </blockquote>
  
  <p>I don't need to aggregate this column or <code>group by</code> it. How do I get this column into my result set? Here is my code:</p>
  
  <pre><code>SELECT  distinct
  la.Limit AS keyfield, 
  convert(varchar(100), se.SourceName) AS SourceEntity,   
  (la.Limit) AS Limit,
  SUM(la.ARLimit) AS LAARLimit,
  SUM(la.MTMLimit) AS LAMTMLimit,
  SUM(la.Volume) AS LAMaxVolume,
  SUM(la.MaxTenor) AS LAMaxTenor, 
  
  SUM(le.ARLimit) AS LEARLimit, 
  SUM(le.MTMLimit) AS LEMTMLimit, 
  SUM(le.Volume) AS LEMAxVolume, 
  SUM(le.MaxTenor) AS LEMaxTenor, SUM(la.ARLimit) + SUM(le.ARLimit) AS [ARLimit], 
  SUM(la.MTMLimit) + SUM(le.MTMLimit) AS [MTMLimit], 
  SUM(la.Volume) + SUM(le.Volume) AS [Volume], 
  SUM(la.MaxTenor) + SUM(le.MaxTenor) AS [MaxTenor]
  FROM            
  dbo.LimitAllocation AS la 
  INNER JOIN
  
  dbo.LimitExtension AS le ON la.Limit = le.Limit AND la.Limit = le.Limit
  
  inner join 
  
  dbo.SourceEntity as se on la.SourceEntity = le.SourceEntity
  GROUP BY la.Limit
  </code></pre>